Python Syntax
Python syntax refers to the set of rules that define how a Python program is constructed. At its core, syntax encompasses everything from the structure of statements and expressions to the way comments are used and how blocks of code are organized. Python's syntax is renowned for its clarity and simplicity, making it an ideal choice for beginners in programming. Unlike many other languages, Python emphasizes readability, which reduces the cost of program maintenance and development. This emphasis on readability is achieved through the use of whitespace to define code blocks and the avoidance of unnecessary symbols, making Python code almost resemble pseudocode.Execute First Python Code
"Hello World": This is a string, a type of data in Python that represents text. In this case, the text is Hello World.
How it Works:
When you run this statement, Python executes the print() function with "Hello World" as its argument. An argument is a value that you pass to a function to tell it what to do. In this case, you're telling print() to display "Hello World".
Comments
In Python programming, comments are used to include explanations or annotations within the code that are not executed by the interpreter. They serve to enhance code readability, provide context, and document the purpose of various sections of code.Python Single Line Comment
In programming, when you see a line of code with a "#" symbol before it, it means that anything written after the "#" symbol is just a note for humans to read, not for the computer to run. It's like writing a reminder or explanation to yourself or other programmers. The computer ignores everything after the "#" symbol on that line. This helps us understand the code better without affecting how the code works when it runs.Python Multi-line Comment
In Python, there isn't a special way to write comments that span multiple lines directly. Instead, programmers often use several single-line comments, one after another, or they use triple quotes (either ''' or """), even though these are technically used for writing strings, not comments. This helps programmers add comments over several lines to explain their code.Python Variables
Python Keywords Words
Python keywords also known as reserved words, are special words that have predefined meanings and cannot be used as identifiers (such as variable names or function names) in Python code. These reserved words are part of the Python language syntax and serve specific purposes. It's important to avoid using these Keywords words as variable names, function name or a class name to prevent conflicts and ensure the proper functioning of your Python programs. Given below are the Keywords/ Reserved words of Python 3.9.
Keywords | ||||
---|---|---|---|---|
False | None | True | and | as |
assert | async | await | break | class |
continue | def | del | elif | else |
except | finally | for | from | global |
if | import | in | is | lambda |
nonlocal | not | or | pass | raise |
return | try | while | with | yield |
Comments
Post a Comment