Indentation and logical and physical lines
In Python, indentation is used to indicate the scope of code blocks, such as functions, loops, and conditionals. Unlike other programming languages that use braces or brackets, Python uses indentation to show the hierarchy of code blocks.
The standard indentation in Python is four spaces. When a block of code is indented, it means that it belongs to the previous block. For example, in a function definition, the code inside the function must be indented to show that it belongs to the function.
Logical lines are lines of code that make up a single statement or expression in Python. A logical line can span multiple physical lines if it is enclosed in parentheses, brackets, or braces. For example:
makefile
my_list = [ 1, 2, 3, 4, 5, 6 ] result = (2 + 3 + 4 + 5)
Physical lines, on the other hand, are the actual lines of code that are written in the source file. Physical lines can be separated by a newline character or a semicolon (;). However, it is recommended to use a newline character for readability. Overall, indentation and understanding logical and physical lines are important concepts in Python for writing clean, readable, and error-free code.
Apply for Python Certification!
https://www.vskills.in/certification/certified-python-developer