Introduction to Python
Features of Python
1. Python is an open source, free programming language. Its code can be accessed ,modified and
distributed freely under flexible open source license.
2. Python is portable .it means that program developed in python run on all popular and advance
platforms such as Windows, Linux , Mac etc.
3. Python is both compiler and interpreter based language.
SOURCE CODE COMPILER BYTE CODE
BYTE CODE INTERPRETER MACHINE CODE
PVM: -PYTHON VIRTUAL MACHINE
4. Python can be used as procedure oriented language as well as object oriented programming
language.
5. Python efficiently utilize the memory of the computer on which it runs.
Modes of Python:-
Interactive Mode:- In interactive mode user keys in one command at a time and in response to that
command python shell execute the command and display the result.
Script Mode:- In script mode the python command are saved in a logical order to get the desired result.
The logical set of instruction is called script program.
Python comments: - # single line comments
“““ Any message “ “ “
Keywords:- Words that have special meaning are reserved by Python for special purpose and are not
allowed to be used as identifiers.
False If else while return and or
True with is from in break class
Idntifiers:- Identifiers are the user defines name of variable ,list ,dictionary, tuple ,classes etc.
First name : Space not allowed
Last&name : can not have special character.
9thclass : cannot begin with number
Else : keyword not allowed.
Data Types:- Data type specify the kind of a value a variable can store .It helps us to identify
the kind of operation that can be perform on that specific data type.€every value in python has
data type.
Number:- int,flat,complex
SEQUENCE :- LIST,STRING,TUPLE
Maps:-Dictionary
Data Type Conversion:- Data is one of type can be converted into another type using type
conversion built in functions like int(),float(),str().
>>>float(12)
12.0
>>>int(15.7)
15
Types of Operators:-
Arithmetic Operator:-
Name Symbol Example Output
Addition + 2+3 5
Subtraction - 3-2 1
Multiplication * 2*5 10
Division / 7/2 3.5
Remainder % 6%2 0
Exponential ** 2**3 8
Floor Division // 13//4 3
Relational Operator or comparison operator:-
Name Symbol Example Output
Equal to a=5
== b=10
a==b false
Not equal to != a=5
b=10
a==b True
Greater than > a=5
b=10
a>b false
Less than < a=5
b=10
a<b True
Greater than or Equal to >= a=10 True
b=10
a>=b
Less than or Equal to <= a=10
b=10
a<=b True
Logical Operator:-
Name Symbol Example Output
AND and 5<10 and 2<5 True
OR or 5>10 or 2<5 True
NOT not Not(5<10 or 2<5) False
Assigment Operator:-
Symbol Example Output
+= a=5
b=10 a=5+10
a+=b or a=a+b a=15
-+ a=5
b=10 a=5-10
a-=b or a=a-b a=-5
*= a=5
b=10 a=5*10
a*=b or a=a*b a=50
/= a=50
b=10 a=50/10
a/=b or a=a/b a=5
//= a=5
b=10
b//=a 2
%= a=5
b=10
a%=b 5
**= a=2
b=4
a**=b 16
Types of error:-
Syntax Error:- Syntax means writing the code following the rule of python language.Syntax
error is occurred when we violating the rules of python language. There is typing error
,incorrect indentation or incorrect arguments given in a function then python will not be able to
interpret the instruction.
Logical Error:- This kind of error is difficult to find since the program will run correctly but the
desired output is not achieved.if we give a wrong formula but output is correct.
Run time Error:- Runtime error occurs during the execution f a program like wrong input or
output error,undefined objecterror ,division by zero.
a=10
b=0
c=a/b