0% found this document useful (0 votes)
9 views20 pages

Overview of Python Programming Language

Python is a high-level, interpreted programming language created by Guido van Rossum in 1989, known for its simplicity and readability. It supports multiple programming paradigms, including object-oriented and procedural programming, and has extensive libraries for various applications such as web development, data analysis, and machine learning. Despite its advantages, Python has limitations in performance and is not typically used for mobile applications.

Uploaded by

venkat2004
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views20 pages

Overview of Python Programming Language

Python is a high-level, interpreted programming language created by Guido van Rossum in 1989, known for its simplicity and readability. It supports multiple programming paradigms, including object-oriented and procedural programming, and has extensive libraries for various applications such as web development, data analysis, and machine learning. Despite its advantages, Python has limitations in performance and is not typically used for mobile applications.

Uploaded by

venkat2004
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PYTHON

Python is a general purpose, dynamic, high level and interpreted programming


language. It supports Object Oriented programming approach to develop applications. It is
simple and easy to learn and provides lots of high-level data structures (in built library).

➔History of Python:
• Guido van Rossum is the inventor of Python programming language,
he worked as an implementer on a team building a language called
ABC at CWI (Centrum Wiskunde Informatica).
• In the year 1989, he started to prepare a simple scripting language to
resolve the problems of ABC programming language, as part of this,
he prepared a simple virtual machine, a simple parser and a simple
runtime with various parts of ABC programming language.
• The name of Python was selected from the TV show “The Complete
Monty Python’s Circus”, which was broadcasted in BBC channel from
1969 to 1974.
• He developed Python language by taking almost all programming
features from different languages.
• Functional programming features from C language, Object Oriented
Programming features from C++, Scripting language features from
PERL and Shell script and modular programming features from
Modula3.
• He introduced the first version of Python in February 1991 with the
version 0.9.0 with the features like Exception Handling, Functions and
the core data types of list, dict, str and so on. The official date is 10th
Feb 1991.
• Python 1.0 was released in January1994. It includes the major new
features like functional programming tools like lambda, map, filter and
reduce…..
• In October 2000, Python 2.0 was released. It has included the
features like list comprehensions, a full garbage collector and
supporting Unicode.
• In December 2008, Python 3.0 version was introduced, it is also called Python3000 or
Py3K, it includes the following enhancements.
Features of Python:
1. Simple and easy to learn: -
→Python is a simple programming language. When we read Python program, we can feel
like reading English statements.
→The syntaxes are very simple and only 30+ keywords are available.
→When compared with other languages, we can write programs with very less number of
lines. Hence more readability and simplicity.
2. Freeware and open source: -
→We can use Python software without any licence and it is freeware.
→Its source code is open, so that we can customize based on our requirements.
→Ex: Jython is customized version of Python to work with Java applications.
3. High level programming language: -
→Python is high level programming language and hence it is programmer friendly language.
→Being a programmer we are not required to concentrate low level activities like memory
management and security etc.
4. Platform independent: -
→Once we write a Python program, it can run on any platform without rewriting once again.
→Internally PVM is responsible to convert into machine understandable form.
5. Portability: -
→That is means programs can migrate from one platform to another platform very easily.
Python programs will provide same results on any machine.
6. Dynamically typed: -
→In Python we are not required to declare type for variables. whenever we are assigning
the value, based on value, type will be allocated automatically. Hence Python is considered
as dynamically typed language.
→But Java, C etc are statically typed languages because we have to provide type at the
beginning only.
→This dynamic typing nature will provide more flexibility to the programmer.
[Link] procedure oriented and Object oriented: -
→Python language supports both procedure oriented (like C, Pascal) and object oriented
(like C++,Java) features. Hence we can get benefits of both like security and reusability.
8. Interpreted: -
→We are not required to compile Python programs explicitly. Internally Python interpreter
will take care that compilation.
→If compilation fails interpreter raised syntax errors. Once compilation success then PVM is
responsible to execute.
9. Multi Threaded: -
→Python is a multiple threaded programming language, because , Python is able to provide
very good environment to create and execute more than one thread at a time.
10. Extensible: -
→We can use other language programs in Python.
→The main advantages of this approach are:
- We can use already existing legacy non-Python code.
- We can improve performance of the application.
11. Embedded: -
→We can use Python programs in any other language programs, that is we can embed
Python programs anywhere.
12. Extensive library: -
→Python has a rich inbuilt library.
→Being a programmer we can use this library directly and we are not responsible to
implement the functionality.

Limitations:
1. Performance wise Python is not up to the mark because it is interpreted language.
2. Not using for mobile applications.

Interpretation vs Compilation:
Interpreter:
This language processor converts high level language program instructions into machine
language by converting and executing it line by line. If there is any error in any line, it reports
it at the same line and program execution cannot resume until the error rectified. Interpreter
must always be present in the memory every time the program is executed as every time the
program is run, it is first interpreted and then executed. For error debugging, interpreter is
very much useful as it reports the error(s) at the same time. But once errors are removed,
unneccesary usage of memory takes place as it has to be present in the memory always.
Compiler:
It is also converts the high level language program instructions into machine language but
the conversion manner is different. It converts the entire program at one time and reports all
the errors of the program along with the line numbers. After all the errors are removed, the
program is recompiled, and after that the compiler is not needed in the memory as the object
program is available.
Python is used to develop: (Applications of Python)
→Desktop applications
→Web applications
→Database applications
→Network applications
→Games
→Data analysis applications
→Machine learning
→Artificial intelligence applications
→Internet Of Things (IOT)
→Data Science applications
Tokens: - The smallest individual unit in a program is known as a Token or lexical unit.
Python has following tokens:
1. Keywords
2. Identifiers
3. Literals
4. Operators
5. Puctuators

Keywords: - A keyword is a word having special meaning reserved by programming


language.

If you see all keywords in Python:


>>>import keyword
>>>[Link]

Identifier:
A name in Python program is called as Identifier. It can be variable name, function
name or class name.
Rules:
1. The only allowed characters are alphabets (a to z, A to Z), digits (0-9) and
underscore(_).
2. Identifier should not start with digit.
3. Identifiers are case sensitive.
4. Identifier cannot be same as reserved word.
5. There is no length limit for identifiers.

Literals: Literals (often reffered to as constant values) are data items that have a fixed
value. Python allows several kinds of literals:
i. String literals
ii. Numeric literals
iii. Boolean literals
iv. Special literal None
v. Literal collections
String literals:
The text enclosed in quotes forms a string literal in Python.
For example, ‘a’, ‘abc’, “abc” are string literals in Python.
Numeric Literals:
The numeric literals in Python can belong to any of the following different numeric types:
Integer literals: Integer literals are whole numbers without any fractional part. An integer
constant must have at least one digit and must not contain any decimal point. It may contain
either +ve or –ve sign.
Ex:
123
-44
Floating point literals: Floating literals are also called real literals. Real literals are numbers
having fractional parts. These may be written in one of the two forms called fractional form
or exponent form.
1. Franctional form consists of signed or unsigned digits including a decimal point between
digits.
Ex:
123.45
3.0
-33.5
2. Exponent form consists of two parts: mantissa and exponent. For instance, 5.8 can be
written as 0.58e1=0.58*101, where mantissa part is 0.58 and exponent part is 1.
Ex:
12.33e3 = 12.33*103=12.33*1000=1233.0

Boolean literals: - A Boolean literal in Python is used to represent one of the two Boolean
values i.e., True or False.
Ex:
True
False
None literal: -Python has one special literal, which is None. The None literal is used to
indicate absence of value. The None value in Python means “There is no useful information”
or “There’s nothing here”.
Ex:
a=None
Operators: -
Operators are special symbols which represents computation. They are applied on
operand(s), which can be values or variables.
Unary operators:
Unary operators are those operators that require one operand to operate.
+ (Unary plus)
- (Unary minus)
~(Bitwise complement)
not logical negation.
Binary operators: -
Binary operators are those operators that require two operands to operate.

1. Arithmetic operators:
+, - , *, /, %
// → floor division operator
15/2 → 7.5
15//2 → 7
** → power operator or Exponent operator
2**3 → 8 (23)
Ex:
a=10
b=2
print("a+b=",a+b)
print("a-b=",a-b)
print("a*b=",a*b)
print("a/b=",a/b)
print("a%b=",a%b)
print("a//b=",a//b)
print("a**b=",a**b)

Note:
→We can use +,* operators for str type also.
→If we want to use + operator for str type then compulsory both arguments should be str
type only otherwise we will get error.
Ex:
>>>"satish"+"k"
satishk
→If we use * operator for str type then compulsory one argument should be int and other
argument should be str type.
>>>2*"satish" (or) "satish"*2
satishsatish

2. Relational operators:
>, >=, <, <=,==, !=
Symbol Description Example 1 Example 2
< Less than >>>7<10 >>>"Hello"< "Goodbye"
True False
>>> 7<5 >>>'Goodbye'< 'Hello'
False True
>>> 7<10<15
True
>>>7<10 and 10<15
True
> Greater than >>>7>5 >>>"Hello"> "Goodbye"
True True
>>>10<10 >>>'Goodbye'> 'Hello'
False False
<= less than equal to >>> 2<=5 >>>"Hello"<= "Goodbye"
True False
>>> 7<=4 >>>'Goodbye' <= 'Hello'
False True
>= greater than equal >>>10>=10 >>>"Hello">="Goodbye"
to True True
>>>10>=12 >>>'Goodbye' >= 'Hello'
False False
! =, <> not equal to >>>10!=11 >>>"Hello"!= "HELLO"
True True
>>>10!=10 >>> "Hello" != "Hello"
False False
== equal to >>>10==10 >>>"Hello" == "Hello"
True True
>>>10==11 >>>"Hello"=="Good Bye"
False False
Note: Two values that are of different data type will never be equal to each other.

Ex:
a=10
b=20
print(a>b)
print(a>=b)
print(a<b)
print(a<=b)
print("satish"<"python")
print(True<False)
print(10>False)

3. Logical Operators: -
and, or, not
Symbol Description
Or If any one of the operand is true, then the
condition becomes true.
And If both the operands are true, then the
condition becomes true.
Not Reverses the state of operand/condition.

Ex:
>>>True and False
False
>>>True or False
True
>>>not False
True

4. Bitwise Operators: -
&, |, ^, ~, <<, >>

These operators are applicable only for int and Boolean values.
& → If both are true it returns True otherwise False
| → If both are false it returns False otherwise True.
^ → If both are different it returns True, if both are same False.
~ Complement
Shift operators:
>> (right shift), << (left shift)
Ex:
>>>10<<2
40

0 0 . . . 1 0 1 0 0 0

25 24 23 22 21 20

32+8=40
>>>10>>2
2

0 0 0 0 0 . . . 1 0 1 0

5. Assignment operator: -
=
We can use assignment operator to assign value to the variable.
Ex:
>>>x=10
>>>a,b,c,d=10,20,30,40
Compound assignment operators
We can combine assignment operator with some other operator to form compound
assignment operator.
+=, -=, *=, /=, %=, //=, **=
&=, |=, ^=, >>=, <<=
Ex:
>>>a=10
>>>a+=5 (a=a+5)
>>>a
15

6. Identity operators:
We can use identity operators for address comparision.
is, is not
7. Membership operators:
We can use membership operators to check whether the given object present in the given
collection.
in, not in
in: "in" operator return true if a character or the entire substring is present in the specified
string, otherwise false.
not in: "not in" operator return true if a character or entire substring does not exist in the
specified string, otherwise false.

Ex:
>>>x="Hello Python programming"
>>>print("h" in x)
True
>>>print("z" in x)
False
>>>print("h" not in x)
False
>>>print("z" not in x)
True
>>>list1=["satish","lokesh","rajesh","lohit"]
>>>print(‘lokesh’ in list1)
True
Operator precedence
10+2*3 → 16
()
**
~, - (unary minus)
*, /, %,//
+, -
<<, >>
&
^
|
>, >=, <, <=, ==, !=
=, +=, -=, …….
is, is not
in, not in
not
and
or
Data type: -
→Data type represents the type of data present inside a variable.
→In Python, we are not required to specify the type explicitly. Based on value provided, the
type will be assigned automatically. Hence Python is dynamically typed language.
→ Fundamental data types in Python:
int, float, complex, bool and str

int data type: -


→It is used to accept whole numbers(integral values).
→It does not have a decimal point.
Ex:
a=10
type(a) #<class ‘int’>

float data type: - It allows fractional numbers.


>>>a=12.34
>>>type(a)
<class ‘float’>

We can provide values exponent form also.


>>>f=1.2e3 (1.2*103=1.2*1000=1200.0)
>>>f
1200.0

complex data type: Complex number in python is made up of two floating point values, one
is real part and another is imaginary part. For accessing different parts of variable (object) x;
we will use [Link] and [Link]. Imaginary part of the number is represented by "j" instead of
"i", so 1+0j denotes zero imaginary part.
A complex number is of the form:
a+bj
a→real part
b→imaginary part
j→j2=-1 →j=sqrt(-1)
→a and b contain integers or floating point values.
Ex:
>>>a=10+20j
>>>type(a)
<class ‘complex’>
>>>[Link]
10
>>>[Link]
20

bool data type: - It represent Boolean values. This data type allows only True or False.
Internally Python represents as True=1 and False=0.

>>>b=True
>>>type(b)
<class ‘bool’>
>>>a=10
>>>b=20
>>>r=a>b
>>>r
False
>>>type(r)
<class ‘bool’>

str data type: - To represent the sequence of characters. String values enclosed in single
quotes or double quotes.
>>>x=’satish’
>>>type(x)
<class ‘str’>
>>>x=”lokesh”
>>>type(x)
<class ‘str’>
Type Conversions: -
We can convert one type of value to another type. This conversion is called Type casting.
In Python, pre-defined functions to perform type casting.

→int(): - To convert any other type to int except complex type.


>>>int(123.45)
123
>>>int(True)
1
>>>int(‘12’)
12

→float(): - To convert any other type to float except complex type.


>>>float(123)
123.0
>>>float(True)
1.0
>>>float(’12.34’)
12.34

→complex(): - To convert any other type to complex type.


Form1: complex(x)
We can use this function to convert x into complex number with real part x and imaginary
part 0.
>>>complex(10)
10+0j
>>>complex(True)
1+0j
>>>complex(12.5)
12.5+0j
>>>complex(‘10’)
10+0j

Form2: complex(x,y)
We can use this method to convert x and y into complex number such that x will be real part
and y will be imaginary part.
>>>complex(10,20)
10+20j
>>>complex(10.5,20.5)
10.5+20.5j
>>>complex(True,False)
1+0j

→bool(): - To convert any other type to bool type.


If int type 0 is False, non-zero is True.
>>>bool(0)
False
>>>int(122)
True
If float type, if total number evaluates 0 it returns False, otherwise it returns True.
>>>bool(12.34)
True
>>>bool(0.000)
False
>>>bool(0.123)
True
If complex type, if both real and imaginary part is 0 it returns False, otherwise it returns True.
>>>bool(0+0j)
False
>>>bool(10+20j)
True
>>>bool(0+10j)
True

If str type, if empty string then it becomes False otherwise it returns True.
>>>bool(‘satish’)
True
>>>bool(‘’)
False

→str(): - To convert any other type to str type.


>>>str(10)
‘10’
>>>str(True)
‘True’
>>>str(12.34)
’12.34’
>>>str(0b1111)
‘15’
>>>str(10+5j)
‘10+5j’
Input and output statements:
print(): - This function is used to display any type of information on the screen.
Form1:
print() →Blank line
It prints new line character.

Form2:
print(string)
Ex:
print("satish")
print()
print("lokesh")

Form3: print with sep attribute


By default we can print multiple values in print statement and they are separated by space. If
you want to change the separator symbol then we use sep attribute.
Ex:
a,b,c,d=10,20,30,40
print(a,b,c,d)
output: 10 20 30 40

Ex:
a,b,c,d=10,20,30,40
print(a,b,c,d,sep=',')
output: 10,20,30,40

Form4: end attribute


By default print statement automatically ends with a ‘\n’. To remove \n in print statement
then we use end attribute.
Ex:
a,b,c,d=10,20,30,40
print(a,end=' ')
print(b,end=' ')
print(c,end=' ')
print(d,end=' ')
output: 10 20 30 40
Form 5:
.format()
{} → it is replacement operator.
Ex:
name='satish'
sal=20000
print("Name is {} and salary is {}".format(name,sal))

Reading dynamic input from the keyboard:


input(): - This function is used to read data from the keyboard in string form.
Syntax:
input ([prompt])

Optional

If prompt is present, it is displayed on monitor, after which the user can provide data from
keyboard. Input takes whatever is typed from the keyboard and evaluates it. As the input
provided is evaluated, it expects valid python expression. If the input provided is not correct
then either syntax error or exception is raised by python.
Ex:
>>>x=input("Enter something:")
>>>type(x)
<class ‘str’>

Ex: Sum of two numbers.


x=int(input("Enter first no:"))
y=int(input("Enter second no:"))
print("sum=",(x+y))

Comments:
→Comments are used to write description about application logics to understand the logics
easily.
→The main objective of comment is code maintenance will become easy.
→The comments are non-executable code.
There are two types of comments in python.
1. Single line comment: Write the description in single line and it starts with #
Syntax: # statement
2. Multiline comments: Write the description in more than one line starts with “”” ends with :
“”””(triple quotes)
→In Python while writing the comments we can write triple double quotes or triple single
quotes (“””) or (‘’’)
Syntax :
“””
St-1
St-2
;;;;;;;;
St-n
“””
Syntax :
‘’’
St-1
St-2
;;;;;;;;
St-n
‘’’

You might also like