- It is very simple to write and execute any Python Program.
- Python Program can be executed directly in the command line .
print("Hello Python")
- C ,C++,Java etc languages use braces to indicate blocks of code for class and function definitions or flow control.
- But Python uses indentation to indicate a block of code.
- We can use at least one space for indentation.
- indentation is a very important element in Python because if you forget or skip the indentation then you will get an error in program.
Program: Greatest value in two number
a=5
b=10
if a>b:
print("a is greater than b")
else:
print("b is greater than a")
- Python code will raise an error if you skip indentation.
a=5
b=10
if a>b:
#this line will raise an error
#because no indentation
print("a is greater than b")
else:
print("b is greater than a")
"""
***Output***
Indentation Error: expected an indented block
"""
- You can use number of spaces for indentation but spaces must be same in the same block of code.
a=5
b=10
if a>b:
print("a is greater than b")
print("means b is less than a")
else:
print("b is greater than a")
print("means a is less than b")
"""
***Output***
b is greater than a
means a is less than b
"""
Request:-If you found this post helpful then let me know by your comment and share it with your friend.
If you want to ask a question or want to suggest then type your question or suggestion in comment box so that we could do something new for you all.
If you have not subscribed my website then please subscribe my website. Try to learn something new and teach something new to other.
Thanks.😊
0 Comments