Getting Started<\/strong>: Learn the basics of installing Python and writing your first program.<\/li><\/ul>\",\"source\":\"https:\/\/cdnvideos.geeksforgeeks.org\/hls\/68cabe99d4b73f578c6c06736d23959cgfg-Python Introduction.m3u8\",\"category\":[{\"term_id__id\":10,\"term_id__term_name\":\"Python\",\"term_id__term_type\":1,\"term_id__slug\":\"python\"},{\"term_id__id\":166,\"term_id__term_name\":\"courses populated\",\"term_id__term_type\":2,\"term_id__slug\":\"courses-populated\"}],\"meta\":{\"thumbnail\":\"https:\/\/media.geeksforgeeks.org\/courses\/PythonIntroduction\/PythonIntroduction20241108170605-small.png\",\"largeThumbnail\":\"https:\/\/media.geeksforgeeks.org\/courses\/PythonIntroduction\/PythonIntroduction20241108170605.jpg\",\"likes\":28,\"views\":1426880,\"isFeatured\":0,\"isPremium\":0,\"isPublic\":1,\"format\":0,\"revision\":{}},\"time\":\"30\/08\/2020\",\"subtitle\":\"https:\/\/cdnvideos.geeksforgeeks.org\/subtitles\/68cabe99d4b73f578c6c06736d23959cgfg-Python Introduction.vtt\",\"duration\":376,\"course_link\":\"https:\/\/www.geeksforgeeks.org\/courses\/master-python-complete-beginner-to-advanced\",\"video_schema\":{\"@context\":\"https:\/\/schema.org\",\"@type\":\"VideoObject\",\"name\":\"Python Introduction\",\"description\":\"Python Introduction nbspPython is a high-level, interpreted programming language known for its simplicity and readability. It was created by Guido van Rossum and first released in 1991. Python has since become one of the most popular programming languages due to its versatility and wide range of applications.Key Features of PythonEasy to Learn and Use Pythons syntax is designed to be clear and intuitive, making it an excellent choice for beginners and experienced programmers alike.Interpreted Language Python code is executed line by line, which allows for easy debugging and makes it more flexible compared to compiled languages.Dynamic Typing Variables in Python do not require explicit declaration of their type, allowing for greater flexibility in coding.Extensive Libraries and Frameworks Python has a rich ecosystem of libraries and frameworks (such as NumPy, pandas, Flask, and Django) that facilitate development across various domains, including web development, data analysis, artificial intelligence, and scientific computing.Cross-Platform Compatibility Python runs on various operating systems, including Windows, macOS, and Linux, making it a versatile choice for developers.Applications of PythonWeb Development Python is widely used for developing web applications using frameworks like Django and Flask, enabling rapid development and deployment.Data Science and Machine Learning With libraries like pandas, NumPy, and TensorFlow, Python is a popular choice for data analysis, visualization, and building machine learning models.Scripting and Automation Pythons simplicity makes it an excellent choice for writing scripts to automate repetitive tasks and improve productivity.Game Development Python can also be used to create games, with libraries like Pygame providing the tools necessary for game development.Scientific Computing Researchers and scientists use Python for numerical computations, simulations, and data analysis, thanks to libraries like SciPy and Matplotlib.Why Learn Python?Versatile Skill Pythons broad applications mean that learning it can open doors to various career paths in technology and beyond.Strong Community Support Python has a large and active community, which means plenty of resources, tutorials, and forums are available for learners at all levels.Future-Proof Language With its growing popularity in fields such as data science and AI, Python skills are in high demand in the job market.Getting Started with PythonInstallation To begin coding in Python, you need to install Python from the official Python website.Integrated Development Environment (IDE) Choose an IDE or text editor for coding. Popular choices include PyCharm, Visual Studio Code, and Jupyter Notebook.Write Your First Program A simple Hello, World program is a great way to startExplore Python Basics Familiarize yourself with Python syntax, data types, control structures, functions, and modules.ConclusionPython is a versatile and powerful programming language that has gained immense popularity across various domains. Whether you are a beginner looking to start your programming journey or an experienced developer seeking to expand your skill set, Python offers a welcoming and rich environment for learning and development.Topics CoveredKey Features of Python Understand the characteristics that make Python a preferred choice for many developers.Applications of Python Explore the diverse fields where Python is used effectively.Getting Started Learn the basics of installing Python and writing your first program.\",\"thumbnailUrl\":[\"https:\/\/media.geeksforgeeks.org\/courses\/PythonIntroduction\/PythonIntroduction20241108170605.jpg\",\"https:\/\/media.geeksforgeeks.org\/courses\/PythonIntroduction\/PythonIntroduction20241108170605-seo.png\",\"https:\/\/media.geeksforgeeks.org\/courses\/PythonIntroduction\/PythonIntroduction20241108170605-small.png\"],\"uploadDate\":\"2020-08-30T20:13:46Z\",\"duration\":\"PT0H6M16S\",\"contentUrl\":\"https:\/\/www.geeksforgeeks.org\/videos\/python-introduction-wlhwxx\/\"}},{\"id\":4037,\"title\":\"How Python Programs are Executed\",\"slug\":\"how-python-programs-are-executed-ysy4e8\",\"description\":\"How Python Programs are Executed | Comprehensive Guide<\/h3> In this tutorial, we will explore How Python Programs are Executed<\/strong>, detailing the process that occurs from writing code to running a Python program. Understanding this execution process is crucial for optimizing performance and debugging effectively.<\/p>Key Features of Python Execution<\/h3>Interpreted Language<\/strong>: Python is an interpreted language, meaning that Python code is executed line by line by an interpreter. This allows for easier debugging and testing, as errors can be identified quickly during execution.<\/li>Dynamic Typing<\/strong>: Python employs dynamic typing, allowing variables to change types at runtime. This flexibility can impact how programs are executed, especially concerning memory management and performance.<\/li>Cross-Platform Compatibility<\/strong>: Python code can be executed on various operating systems without modification, provided the appropriate interpreter is installed.<\/li><\/ul>Steps in the Execution of a Python Program<\/h3>Writing the Code<\/strong>: Developers write Python code in a text editor or an Integrated Development Environment (IDE) and save it with a .py extension.<\/li>Lexical Analysis<\/strong>: When the Python interpreter runs the program, it first performs lexical analysis, breaking the source code into tokens (keywords, identifiers, literals, etc.).<\/li>Parsing<\/strong>: The interpreter then parses these tokens to create an Abstract Syntax Tree (AST). This tree represents the hierarchical structure of the code, enabling the interpreter to understand its semantics.<\/li>Bytecode Compilation<\/strong>: Next, the AST is compiled into bytecode, a low-level representation of the source code that is platform-independent. This bytecode is stored in .pyc files to improve execution speed for subsequent runs.<\/li>Execution by the Python Virtual Machine (PVM)<\/strong>: The bytecode is then executed by the Python Virtual Machine (PVM). The PVM interprets the bytecode line by line and translates it into machine code, which the underlying hardware can execute.<\/li>Memory Management<\/strong>: During execution, Python manages memory using a technique called garbage collection, which automatically deallocates memory that is no longer in use, helping to optimize performance.<\/li><\/ul>Common Operations During Execution<\/h3>Importing Modules<\/strong>: When a Python program imports a module, the interpreter executes the module\u2019s code, which may include defining functions, classes, or initializing data structures.<\/li>Error Handling<\/strong>: If the interpreter encounters an error during any phase of execution (syntax errors, runtime errors, etc.), it raises an exception and provides feedback, allowing the developer to debug the code.<\/li>Optimizations<\/strong>: The Python interpreter may perform certain optimizations during bytecode compilation and execution, such as caching frequently used bytecode.<\/li><\/ul>Common Mistakes to Avoid<\/h3>Ignoring Indentation<\/strong>: Python relies on indentation to define code blocks. Incorrect indentation can lead to syntax errors or logical errors in the program.<\/li>Not Handling Exceptions<\/strong>: Failing to properly handle exceptions can cause programs to crash unexpectedly. Use try-except blocks to manage errors gracefully.<\/li>Overlooking Performance<\/strong>: Be aware of performance issues, especially in large programs or those with complex data structures. Regular profiling and optimization can enhance execution speed.<\/li><\/ul>Applications of Understanding Execution<\/h3>Debugging<\/strong>: Knowing how Python executes code helps in identifying and resolving issues quickly, improving the overall development process.<\/li>Performance Optimization<\/strong>: Understanding the execution process allows developers to write more efficient code, making informed decisions about memory management and performance improvements.<\/li>Effective Use of Libraries<\/strong>: Grasping how imports and modules are executed can help in utilizing third-party libraries more effectively, avoiding common pitfalls.<\/li><\/ul>Why Learn About Python Execution?<\/h3> Understanding how Python programs are executed is essential for both beginners and experienced developers. By mastering this topic, you will:<\/p>
Enhance Your Python Skills<\/strong>: Gain a deeper insight into the inner workings of Python, improving your ability to write efficient and effective code.<\/li>Write More Robust Programs<\/strong>: Knowledge of execution allows for better error handling and debugging practices, resulting in more stable applications.<\/li>Optimize Performance<\/strong>: Learn to identify bottlenecks and optimize your code for better performance in various applications.<\/li><\/ul>Topics Covered<\/h3>Introduction to Python Execution<\/strong>: Understand the basics and significance of Python program execution.<\/li>Steps in Execution<\/strong>: Explore the detailed steps involved from writing code to executing it.<\/li>Common Operations and Mistakes<\/strong>: Learn about common operations during execution and mistakes to avoid.<\/li><\/ul>\",\"source\":\"https:\/\/cdnvideos.geeksforgeeks.org\/hls\/e635e2a48a44803676ae5362c4fe1493gfg-How Python Programs are Executed.m3u8\",\"category\":[{\"term_id__id\":10,\"term_id__term_name\":\"Python\",\"term_id__term_type\":1,\"term_id__slug\":\"python\"},{\"term_id__id\":166,\"term_id__term_name\":\"courses populated\",\"term_id__term_type\":2,\"term_id__slug\":\"courses-populated\"}],\"meta\":{\"thumbnail\":\"https:\/\/media.geeksforgeeks.org\/courses\/HowPythonProgramsareExecuted\/HowPythonProgramsareExecuted20241108170233-small.png\",\"largeThumbnail\":\"https:\/\/media.geeksforgeeks.org\/courses\/HowPythonProgramsareExecuted\/HowPythonProgramsareExecuted20241108170233.jpg\",\"likes\":0,\"views\":313980,\"isFeatured\":0,\"isPremium\":0,\"isPublic\":1,\"format\":0,\"revision\":{}},\"time\":\"30\/08\/2020\",\"subtitle\":\"https:\/\/cdnvideos.geeksforgeeks.org\/subtitles\/e635e2a48a44803676ae5362c4fe1493gfg-How Python Programs are Executed.vtt\",\"duration\":540,\"course_link\":\"https:\/\/www.geeksforgeeks.org\/courses\/master-python-complete-beginner-to-advanced\"},{\"id\":4042,\"title\":\"Python Programming Terminology\",\"slug\":\"python-programming-terminology-ri0xvs\",\"description\":\"Python program terminology<\/strong> refers to the key concepts and components used in writing and understanding Python code. It includes terms like variables<\/strong>, data types<\/strong>, functions<\/strong>, and loops<\/strong>, which form the building blocks of a Python program. Modules<\/strong> and packages<\/strong> help organize and reuse code, while objects<\/strong> and classes<\/strong> are fundamental in object-oriented programming. Additionally, exceptions<\/strong> manage errors, and indentation<\/strong> is crucial for defining code structure in Python. Mastering these terms is essential for writing efficient and error-free Python code.<\/p>\",\"source\":\"https:\/\/cdnvideos.geeksforgeeks.org\/hls\/fbe37f37cb1e0fa1fe79f81829627eccgfg-Python Programming Terminology.m3u8\",\"category\":[{\"term_id__id\":10,\"term_id__term_name\":\"Python\",\"term_id__term_type\":1,\"term_id__slug\":\"python\"},{\"term_id__id\":166,\"term_id__term_name\":\"courses populated\",\"term_id__term_type\":2,\"term_id__slug\":\"courses-populated\"}],\"meta\":{\"thumbnail\":\"https:\/\/media.geeksforgeeks.org\/courses\/PythonProgrammingTerminology\/PythonProgramTerminology20241129182254-small.png\",\"largeThumbnail\":\"https:\/\/media.geeksforgeeks.org\/courses\/PythonProgrammingTerminology\/PythonProgramTerminology20241129182254.jpg\",\"likes\":0,\"views\":188070,\"isFeatured\":0,\"isPremium\":0,\"isPublic\":1,\"format\":0,\"revision\":{}},\"time\":\"30\/08\/2020\",\"subtitle\":\"https:\/\/cdnvideos.geeksforgeeks.org\/subtitles\/fbe37f37cb1e0fa1fe79f81829627eccgfg-Python Programming Terminology.vtt\",\"duration\":642,\"course_link\":\"https:\/\/www.geeksforgeeks.org\/courses\/master-python-complete-beginner-to-advanced\"},{\"id\":4043,\"title\":\"Python Installation and First Program\",\"slug\":\"python-installation-and-first-program-3huqwn\",\"description\":\"Python installation on Windows<\/strong> is a straightforward process that can be completed with just a few simple steps. Once installed, you can begin writing your first Python program to get hands-on experience with the language. This guide walks you through the process of downloading, installing, and configuring Python on your Windows computer. For installation on other operating systems like Linux or Mac, alternative guides are available. Start your Python journey today with easy installation and your first program. <\/p>\",\"source\":\"https:\/\/cdnvideos.geeksforgeeks.org\/hls\/ef2e82182f5255eab97dee4adbd7d3e1gfg-Python Indtallation.m3u8\",\"category\":[{\"term_id__id\":10,\"term_id__term_name\":\"Python\",\"term_id__term_type\":1,\"term_id__slug\":\"python\"},{\"term_id__id\":166,\"term_id__term_name\":\"courses populated\",\"term_id__term_type\":2,\"term_id__slug\":\"courses-populated\"}],\"meta\":{\"thumbnail\":\"https:\/\/media.geeksforgeeks.org\/courses\/PythonInstallationandFirstProgram\/PythonInstallationandFirstProgram20241129182333-small.png\",\"largeThumbnail\":\"https:\/\/media.geeksforgeeks.org\/courses\/PythonInstallationandFirstProgram\/PythonInstallationandFirstProgram20241129182333.jpg\",\"likes\":0,\"views\":563980,\"isFeatured\":0,\"isPremium\":0,\"isPublic\":1,\"format\":0,\"revision\":{}},\"time\":\"01\/09\/2020\",\"subtitle\":\"https:\/\/cdnvideos.geeksforgeeks.org\/subtitles\/ef2e82182f5255eab97dee4adbd7d3e1gfg-Python Indtallation.vtt\",\"duration\":704,\"course_link\":\"https:\/\/www.geeksforgeeks.org\/courses\/master-python-complete-beginner-to-advanced\"},{\"id\":3969,\"title\":\"Comments in Python\",\"slug\":\"comments-in-python-zcqbig\",\"description\":\"Comments in Python <\/h2> In this tutorial, we will explore Comments in Python<\/strong>, an essential feature that enhances code readability and maintainability. Comments are annotations in the code that are ignored by the Python interpreter but provide valuable context for anyone reading the code.<\/p>Key Features of Comments<\/h3>Improves Code Readability<\/strong>: Comments help explain complex code logic, making it easier for others (or yourself in the future) to understand the code's purpose and functionality.<\/li>Facilitates Collaboration<\/strong>: In collaborative environments, comments provide insights into the thought process behind code changes, helping team members understand the rationale behind specific implementations.<\/li>Documentation<\/strong>: Comments can serve as inline documentation, describing the functionality of functions, classes, and modules, which is especially useful for large codebases.<\/li><\/ul>Types of Comments in Python<\/h3>Single-Line Comments<\/strong>: These begin with the # symbol and extend to the end of the line. They are often used to provide brief explanations or notes about a specific line or section of code.<\/li>Multi-Line Comments<\/strong>: While Python does not have a distinct syntax for multi-line comments, you can achieve them using triple quotes (''' or \\\"\\\"\\\"). While primarily intended for docstrings, triple quotes can also be used to comment out blocks of code or provide detailed explanations.<\/li><\/ul>Best Practices for Using Comments<\/h3>Be Clear and Concise<\/strong>: Write comments that are easy to understand and straight to the point. Avoid overly verbose explanations.<\/li>Keep Comments Up-to-Date<\/strong>: Ensure that comments accurately reflect the current state of the code. Outdated comments can lead to confusion and misunderstandings.<\/li>Avoid Redundant Comments<\/strong>: Don't state the obvious. Focus on explaining the \\\"why\\\" rather than the \\\"what\\\" to add value to your comments.<\/li>Use Comments to Explain Why, Not What<\/strong>: Comments are most helpful when they explain the reasoning behind complex logic or decisions made in the code.<\/li><\/ul>Common Mistakes to Avoid<\/h3>Over-commenting<\/strong>: Excessive comments can clutter code and make it harder to read. Aim for a balance where comments add value without overwhelming the code.<\/li>Neglecting Comments<\/strong>: Failing to use comments in complex or critical sections of code can make maintenance difficult and hinder collaboration.<\/li>Ignoring Style Guides<\/strong>: Follow coding style guides (like PEP 8 for Python) for writing comments, which can help maintain consistency and clarity in your codebase.<\/li><\/ul>Conclusion<\/h3> Comments are a vital part of programming in Python, enhancing code readability, collaboration, and documentation. By effectively using comments, you can create code that is not only functional but also easy to understand and maintain.<\/p>
Topics Covered<\/h3>Introduction to Comments<\/strong>: Understand the significance and purpose of comments in Python.<\/li>Types of Comments<\/strong>: Explore single-line and multi-line comments and their usage.<\/li>Best Practices<\/strong>: Learn best practices for writing effective comments.<\/li>Common Mistakes<\/strong>: Discuss common pitfalls to avoid when using comments.<\/li><\/ul>\",\"source\":\"https:\/\/cdnvideos.geeksforgeeks.org\/hls\/9b08cc996332e3ab979746209bd20da8gfg-Comments In Python.m3u8\",\"category\":[{\"term_id__id\":10,\"term_id__term_name\":\"Python\",\"term_id__term_type\":1,\"term_id__slug\":\"python\"},{\"term_id__id\":166,\"term_id__term_name\":\"courses populated\",\"term_id__term_type\":2,\"term_id__slug\":\"courses-populated\"}],\"meta\":{\"thumbnail\":\"https:\/\/media.geeksforgeeks.org\/courses\/CommentsinPython\/CommentsinPython20241108170732-small.png\",\"largeThumbnail\":\"https:\/\/media.geeksforgeeks.org\/courses\/CommentsinPython\/CommentsinPython20241108170732.jpg\",\"likes\":0,\"views\":107490,\"isFeatured\":0,\"isPremium\":0,\"isPublic\":1,\"format\":0,\"revision\":{}},\"time\":\"07\/08\/2020\",\"subtitle\":\"https:\/\/cdnvideos.geeksforgeeks.org\/subtitles\/9b08cc996332e3ab979746209bd20da8gfg-Comments In Python.vtt\",\"duration\":247,\"course_link\":\"https:\/\/www.geeksforgeeks.org\/courses\/master-python-complete-beginner-to-advanced\"},{\"id\":3956,\"title\":\"Variables in Python\",\"slug\":\"variables-in-python-dc0fg0\",\"description\":\"Variables in Python <\/h2> In this tutorial, we will explore Variables in Python<\/strong>, an essential concept that allows you to store, manage, and manipulate data within your programs. Understanding variables is crucial for effective programming and data handling in Python.<\/p>Key Features of Variables<\/h3>Dynamic Typing<\/strong>: Python uses dynamic typing, meaning you do not need to declare the data type of a variable explicitly. The interpreter determines the type at runtime based on the value assigned.<\/li>No Declaration Required<\/strong>: You can create a variable simply by assigning a value to it, without the need for a specific declaration syntax.<\/li>Flexible Data Types<\/strong>: Python supports various data types, including integers, floats, strings, lists, dictionaries, and more. Variables can hold data of any type, and their type can change dynamically.<\/li><\/ul>How Variables Work in Python<\/h3> When you create a variable, you are essentially creating a name that refers to a value stored in memory. The assignment operator (=) is used to assign values to variables. Once a variable is defined, you can use it throughout your program to refer to the value it holds.<\/p>
Naming Conventions for Variables<\/h3>Descriptive Names<\/strong>: Choose meaningful variable names that describe the data they hold. This enhances code readability and maintainability.<\/li>Follow Syntax Rules<\/strong>: Variable names can include letters, numbers, and underscores, but cannot start with a number. They should not contain special characters or spaces.<\/li>Case Sensitivity<\/strong>: Variable names are case-sensitive. For example, myVariable and myvariable are considered two different variables.<\/li><\/ul>Common Operations with Variables<\/h3>Assignment<\/strong>: Assign values to variables using the assignment operator. You can also assign multiple variables in a single statement.<\/li>Data Manipulation<\/strong>: Perform operations on variables, such as arithmetic calculations, string concatenation, and list operations.<\/li>Updating Variables<\/strong>: Variables can be updated by reassigning them with new values or by performing operations that modify their current value.<\/li><\/ul>Common Mistakes to Avoid<\/h3>Using Undefined Variables<\/strong>: Attempting to use a variable before it has been defined will result in a runtime error. Always ensure that variables are assigned values before use.<\/li>Typographical Errors<\/strong>: Misspelling a variable name can lead to confusion and errors, as Python will treat it as a new variable.<\/li>Ignoring Scope<\/strong>: Be mindful of variable scope (local vs. global). Understanding where a variable can be accessed is crucial for effective programming.<\/li><\/ul>Applications of Variables<\/h3>Data Storage<\/strong>: Variables are used to store data temporarily while a program runs, allowing for dynamic data manipulation.<\/li>Intermediate Calculations<\/strong>: Use variables to hold intermediate results in calculations, making complex operations easier to manage.<\/li>User Input Handling<\/strong>: Variables can store user input for further processing, allowing programs to interact with users effectively.<\/li><\/ul>Why Learn About Variables in Python?<\/h3> Understanding variables is foundational for programming in Python. By mastering this concept, you will:<\/p>
Enhance Your Programming Skills<\/strong>: Gain a solid understanding of how data is stored and manipulated in Python.<\/li>Write More Efficient Code<\/strong>: Learn to manage and use data effectively, improving the overall performance of your applications.<\/li>Develop Practical Applications<\/strong>: Create applications that utilize variables for data management, calculations, and user interactions.<\/li><\/ul>Topics Covered<\/h3>Introduction to Variables<\/strong>: Understand the basics and significance of variables in Python.<\/li>Naming Conventions<\/strong>: Explore best practices for naming variables effectively.<\/li>Common Operations<\/strong>: Learn about operations that can be performed on variables.<\/li>Common Mistakes<\/strong>: Discuss pitfalls to avoid when using variables.<\/li><\/ul>\",\"source\":\"https:\/\/cdnvideos.geeksforgeeks.org\/hls\/aa4addf41175e52e7ba7e94097881fcdgfg-Variables In Python.m3u8\",\"category\":[{\"term_id__id\":10,\"term_id__term_name\":\"Python\",\"term_id__term_type\":1,\"term_id__slug\":\"python\"},{\"term_id__id\":166,\"term_id__term_name\":\"courses populated\",\"term_id__term_type\":2,\"term_id__slug\":\"courses-populated\"}],\"meta\":{\"thumbnail\":\"https:\/\/media.geeksforgeeks.org\/courses\/VariablesinPython\/VariablesinPython20241108171348-small.png\",\"largeThumbnail\":\"https:\/\/media.geeksforgeeks.org\/courses\/VariablesinPython\/VariablesinPython20241108171348.jpg\",\"likes\":0,\"views\":492680,\"isFeatured\":0,\"isPremium\":0,\"isPublic\":1,\"format\":0,\"revision\":{}},\"time\":\"03\/08\/2020\",\"subtitle\":\"https:\/\/cdnvideos.geeksforgeeks.org\/subtitles\/aa4addf41175e52e7ba7e94097881fcdgfg-Variables In Python.vtt\",\"duration\":428,\"course_link\":\"https:\/\/www.geeksforgeeks.org\/courses\/master-python-complete-beginner-to-advanced\"}]");
Python Introduction - GeeksforGeeks
Skip to content
▲
Python Introduction
Last Updated :
13 Oct, 2025
Python was created in 1991 with a focus on code readability and its ability to express concepts in fewer lines of code.
Variable types are determined automatically at runtime, simplifying code writing. Supports multiple programming paradigms, including object-oriented, functional and procedural programming. Understanding Hello World Program in Python The following is a simple program that displays the message “Hello, World!” on the screen.
Python
# This is a comment. It will not be executed.
print ( "Hello, World!" )
How does this work:
print() is a built-in Python function that instructs the computer to display text on the screen. "Hello, World!" is a string, which is a sequence of text. In Python, strings are enclosed in quotes (either single ' or double "). Anything after a # symbol is a comment . Python ignores comments, but they are useful for explaining code to human readers. We can also write multi-line comments using triple quotes:
Python
"""
This is a multi-line comment.
It can be used to describe larger sections of code.
"""
Indentation in Python In Python, Indentation is used to define blocks of code. It tells the Python interpreter that a group of statements belongs to a specific block. All statements with the same level of indentation are considered part of the same block. Indentation is achieved using whitespace (spaces or tabs) at the beginning of each line. The most common convention is to use 4 spaces or a tab, per level of indentation.
Python
print ( "I have no Indentation " )
print ( "I have tab Indentation " )
Output:
ERROR! Traceback (most recent call last): File "<main.py>", line 2 print("I have tab Indentation ") IndentationError: unexpected indent
Explanation:
first print statement has no indentation, so it is correctly executed. second print statement has tab indentation , but it doesn't belong to a new block of code. Python expects the indentation level to be consistent within the same block. This inconsistency causes an IndentationError . Please refer Applications, Advantages and Disadvantages of Python to know about what all we can do with Python.
Python Introduction
How Python Programs are Executed
Python Programming Terminology
Python Installation and First Program
Comments in Python
Variables in Python