Python Devlopment






Introduction



2.0 What is Python?

Python is a popular programming language. It was created in 1991 by Guido van Rossum.

It is used for:

  • web development (server-side)
  • software development
  • mathematics
  • system scripting.

Python Syntax compared to other programming languages

  • Python uses new lines to complete a command, as opposed to other programming languages which often use semicolons or parentheses
  • Python relies on indentation, using whitespace, to define scope; such as the scope of loops, functions and classes. Other programming languages often use curly-brackets for this purpose.

2.0.1 Print command:

Print command is used to display text or data on the screen

>>>print(“Hello,World!!”)
Hello,World!!

To combine both text and a variable, Python uses the + character:

 

a=”Harish”
print(“Hello “+a)
Output:
Hello Harish
a = "Hello "        
b = "Harish"  
c = a + b
print(c)

Output:
Hello Harish

But for numbers, + character works as a mathematical operator:

a = 10
b = 20
print(a + b)

Output: 
30

But combination of different type variable is not possible e.g. If you try to combine a string and a number, Python will give you an error:

a = 10
b = "Harish"
print(a + b)


It will give an errorTypeError:

Unsupported operand type(s) for +: ‘int’ and ‘str’

Forms of print command

print("Hello")
print('Hello')
print "Hello"   #This is recommended in python 2.0

2.0.2 How to write program in any editor:

To write any python program, first open any editor like vm,pico, text or nano and then type python code in it which is given in below examples. After typing complete program code, you can directly run your python program.

2.0.3 How to Run?

In python, we can directly run our program using following syntax

harish@harish-Inspiron-3537:~$ python file_name.py

Example

harish@harish-Inspiron-3537:~$ python sample.py

2.0.4 Python Indentations:

In other programming languages, indentation is used for formating for for readability only but in python indentation is very important. It is used to indicate block of codes

Example:

If 10<20:
    print(“10 is smaller that 20”)

If you type code like

If 10<20:
print(“10 is smaller that 20”)

It will give an error.

But in other languages it will not give error.

2.0.5 Comments:

As like other programming languages, in python also commenting is there. In python, comment starts with # and python interpretter will ignore the rest of the line as a comment.

#This is a comment
print(“Hello, World!”)

Python ignores

# This is a comment

statement.