3. 1.What is Indentation of Python?
• Indentation refers to the spaces at the beginning of a code
line.
• the indentation in Python is very important.
• Python uses indentation to indicate a block of code.
• Python will give you an error if you skip the indentation.
• Example:
• if 5 > 2:
• print("Five is greater than two!")
4. 2. What happens if you don't follow the
correct indentation in Python?
• Incorrect indentation in Python leads to indentation errors and
affects the program's structure.
• Example:
• if 5 > 2:
• print("Five is greater than two!")
5. 3. What is the purpose of indentation
in Python?
• Code Structure
• Readability
• No Explicit Braces or Delimiters
• Example:
6. # Example of indentation in a conditional
statement
if x > 0:
print("x is positive")
y = x * 2
print("Twice x is", y)
else:
print("x is non-positive")
y = 0
print("Y is", y)
8. 5.What are the Rules for Indentation?
• minimum one space is necessary to represent an indented statement.
• The first line of python code cannot have indentation.
• Indentation is mandatory to define a block of code.
• No Closing Braces or Delimiters.
• Indentation After Colon:
9. 6.What is Comments in python?
• Comments can be used to make the code more readable.
• Comments can be used to prevent execution when testing code.
• Indicates the symbol is #.
• Comments starts with a #, and python will ignore on that line of code.
• Example:
• #print("Hello, World!")
• print("Good, morning")
10. 7.What are the Types of Comments?
• These are divided into two types
• Single-line Comment: The comment is applied on the single-line of the code.
• Example:#print(“Hello World”)
• Multiline Comment: The comment is applied on the multiple lines of the code.
Example:""" print(“Hello World”)
print(“Good Evening”)
print(“Good Night”)"""
11. 8. What is the purpose of comments in
Python?
• Comments in Python are used to explain and document code.
• They are not executed and are intended for human readers to
understand the code better.
12. 9.What is the difference between
single-line and multi-line comments in
Python?
Single-line Comment Multi-line Comment
• Multi-line comments are created using
triple quotes(” ” ”)
• Example:
""" print(“Hello World”)
print(“Good Evening”)
print(“Good Night”)"""
• Single-line comments start with a hash
symbol(‘#’)
• Example:#print(“Good Morning”)
• print(“Hello Mumbai”)
13. 10. When should you use comments in
your code?
• Comments should be used to explain complex parts of the code.
• Debug the code apply the comment.