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

Python: Indentation, Comments

Barbara Streisand
Release: 2024-11-07 17:26:02
Original
785 people have browsed it

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")
Copy after login

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")
Copy after login

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!") 
Copy after login

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")
Copy after login

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!")
Copy after login

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!")
Copy after login

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

source:dev.to
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template