Hi All, Today i started to learn python.
INDENTATION
- Python uses indentation to
indicate
the block of code. - Space is use to specify the indentation in the
beginning of code
. - Most common indentation use
four
, and has to be use at leastone
space.(Don't use rest number of spaces it will generate syntax error)
if 10>1
print("Ten is greater than one")
Should be use same no. of spaces in the same block of code otherwise will generate error.
if 10>1
print("Ten is greater than one")
print("Ten is lower than one")
The spaces use different no. of counts in two diff block of code.
if 5 > 2
print("Five is greater than two!")
if 5 > 2
print("Five is greater than two!")
COMMENT
Single Line Comment
- Comment start with
# in the code
. where we indicate the # in the line of code the line should be ignored to read. - If we use
#
in the end of line and python wouldn't read rest of the line in code.
#print("Hello Python")
print("Hello Python")
Multi Line Comment
Since Python not have multi line comment. We will use #
with each line which all we want ignore to read python.
#This is a comment
#written in
#just more than one line
print("Hello, World!")
And as long as the string not assigned to a variable, python will read the line but then ignore it. We use triple quotes to use multi line comments.
"""
This is a comment
written in
just more than one line
"""
print("Hello, World!")