First Program in Python

First Program

  • It is terribly easy to put in writing and execute any Python Program.
  • Python Program may be executed directly within the command.
print("Hello Python")

Indentation in Python
  • C ,C++,Java etc. languages use braces to point blocks of code for sophistication and performance definitions or flow management.
  • But Python uses indentation to point a block of code.
  • We can use a minimum of one space for indentation.
  • indentation could be a important component in Python as a result of if you forget or skip the indentation then you may get a 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 range of areas for indentation however areas should be same within 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
"""