First python program in python?

 First Program

  • 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.
a=5
b=10
if a>b:
    print("a is greter 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 lin will raise an error
#because no indentation
print("a is greter than b")
else:
    print("b is greater than a")
"""
***Output***
IndentationError: 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 greter 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
"""

Comments

Popular posts from this blog

What is computer programming?

Computer programming languages?