Home  >  Article  >  Backend Development  >  Python: Indentation, Comments

Python: Indentation, Comments

Barbara Streisand
Barbara StreisandOriginal
2024-11-07 17:26:02650browse

Python: Indentation, Comments

Hi All, Today i started to learn python.

INDENTATION

  1. Python uses indentation to indicate the block of code.
  2. Space is use to specify the indentation in the beginning of code.
  3. Most common indentation use four, and has to be use at least one 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

  1. Comment start with # in the code. where we indicate the # in the line of code the line should be ignored to read.
  2. 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!")

The above is the detailed content of Python: Indentation, Comments. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn