Syntax, Intentation and Comment
Syntax
A syntax defines that how a program would written. Syntax is like a rule that should be followed when writing the code. For example :
- Using indentation for writing code blocks.
- Python is case sensitive (John and john are treated differently).
- Variables donn't need explicit types.
- It doesn't use ; for line end.
Indentation
In python, any number of empty space at the starting in code lines are called Indentation. It is used for difining code block and writing pretty codes.
Each line within a code block should have equal indentation.
if a==1:
print(a) #indentation
print("end")#indentation
Comment
Comments are the code that doesn't get executed, and commonly used for explaining/understanding the code.
There are 2 common types of comments -
- Single line comment
- Multi-line comment
Single line comment
Single line comments are used to make only a single as comment. It is done using adding # symbol as first character of comment. Character written after # are considered as a comment.
# single line comment
a=1 # single line comment
Multi-line comment
Pyhton doesn't have any multi line comment feature, but an unassigned multi-line string works similar like a multi line comment. It can be created with 3 single/double opening and closing quotes. """ """ or ''' '''
"""
Hey there
share it if you find
it helpfull, (multi line comment/string)
"""