0% found this document useful (0 votes)
28 views

1 - Basics

Python is a popular programming language created by Guido van Rossum in 1991. It is used for web development, software development, mathematics, and system scripting. Python has undergone many versions since its initial release in 1994 with new features and support added regularly. It is a high-level, general purpose programming language known for its simple syntax and readability.

Uploaded by

Naveen Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

1 - Basics

Python is a popular programming language created by Guido van Rossum in 1991. It is used for web development, software development, mathematics, and system scripting. Python has undergone many versions since its initial release in 1994 with new features and support added regularly. It is a high-level, general purpose programming language known for its simple syntax and readability.

Uploaded by

Naveen Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

What is Python?

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

It is used for:

 web development (server-side),


 software development,
 mathematics,
 system scripting.

Python History
o Python laid its foundation in the late 1980s.
o The implementation of Python was started in the December 1989 by Guido Van
Rossum at CWI in Netherland.
o In February 1991, van Rossum published the code (labeled version 0.9.0) to alt.sources.
o In 1994, Python 1.0 was released with new features like: lambda, map, filter, and
reduce.
o Python 2.0 added new features like: list comprehensions, garbage collection system.
o On December 3, 2008, Python 3.0 (also called "Py3K") was released. It was designed to
rectify fundamental flaw of the language.
o ABC programming language is said to be the predecessor of Python language which was
capable of Exception Handling and interfacing with Amoeba Operating System.
o Python is influenced by following programming languages:
o ABC language.
o Modula-3

Python Version
Python programming language is being updated regularly with new features and supports.
There are lots of updations in python versions, started from 1994 to current release.

A list of python versions with its released date is given below.

Python Version Released Date

Python 1.0 January 1994


Python 1.5 December 31, 1997
Python 1.6 September 5, 2000
Python 2.0 October 16, 2000
Python 2.1 April 17, 2001
Python 2.2 December 21, 2001
Python 2.3 July 29, 2003
Python 2.4 November 30, 2004
Python 2.5 September 19, 2006
Python 2.6 October 1, 2008
Python 2.7 July 3, 2010
Python 3.0 December 3, 2008
Python 3.1 June 27, 2009
Python 3.2 February 20, 2011
Python 3.3 September 29, 2012
Python 3.4 March 16, 2014
Python 3.5 September 13, 2015
Python 3.6 December 23, 2016
Python 3.6.4 December 19, 2017

Python Applications Area


Python is known for its general purpose nature that makes it applicable in almost each domain
of software development. Python as a whole can be used in any sphere of development.

Here, we are specifying applications areas where python can be applied.

1) Web Applications

We can use Python to develop web applications. It provides libraries to handle internet
protocols such as HTML and XML, JSON, Email processing, request, beautifulSoup, Feedparser
etc. It also provides Frameworks such as Django, Pyramid, Flask etc to design and delelop web
based applications. Some important developments are: PythonWikiEngines, Pocoo,
PythonBlogSoftware etc.

2) Desktop GUI Applications


Python provides Tk GUI library to develop user interface in python based application. Some
other useful toolkits wxWidgets, Kivy, pyqt that are useable on several platforms. The Kivy is
popular for writing multitouch applications.

3) Software Development

Python is helpful for software development process. It works as a support language and can be
used for build control and management, testing etc.

4) Scientific and Numeric

Python is popular and widely used in scientific and numeric computing. Some useful library and
package are SciPy, Pandas, IPython etc. SciPy is group of packages of engineering, science and
mathematics.

5) Business Applications

Python is used to build Business applications like ERP and e-commerce systems. Tryton is a high
level application platform.

6) Console Based Application

We can use Python to develop console based applications. For example: IPython.

7) Audio or Video based Applications

Python is awesome to perform multiple tasks and can be used to develop multimedia
applications. Some of real applications are: TimPlayer, cplay etc.

8) 3D CAD Applications

To create CAD application Fandango is a real application which provides full features of CAD.

9) Enterprise Applications

Python can be used to create applications which can be used within an Enterprise or an
Organization. Some real time applications are: OpenErp, Tryton, Picalo etc.

10) Applications for Images

Using Python several application can be developed for image. Applications developed are:
VPython, Gogh, imgSeek etc.

There are several such applications which can be developed using Python
Python Features

Python provides lots of features that are listed below.

1) Easy to Learn and Use


Python is easy to learn and use. It is developer-friendly and high level programming language.

2) Expressive Language

Python language is more expressive means that it is more understandable and readable.

3) Interpreted Language

Python is an interpreted language i.e. interpreter executes the code line by line at a time. This
makes debugging easy and thus suitable for beginners.

4) Cross-platform Language

Python can run equally on different platforms such as Windows, Linux, Unix and Macintosh etc.
So, we can say that Python is a portable language.

5) Free and Open Source

Python language is freely available at official web address. The source-code is also available.
Therefore it is open source.

6) Object-Oriented Language

Python supports object oriented language and concepts of classes and objects come into
existence.

7) Extensible

It implies that other languages such as C/C++ can be used to compile the code and thus it can
be used further in our python code.

8) Large Standard Library


Python has a large and broad library and provides rich set of module and functions for rapid
application development.

9) GUI Programming Support

Graphical user interfaces can be developed using Python.

10) Integrated

It can be easily integrated with languages like C, C++, JAVA etc.

Python Variables
 Variable is a name which is used to refer memory location. Variable also known as
identifier and used to hold value.
 In Python, we don't need to specify the type of variable because Python is a type infer
language and smart enough to get variable type.
 Variable names can be a group of both letters and digits, but they have to begin with a
letter or an underscore.
 It is recommended to use lowercase letters for variable name. Rahul and rahul both
are two different variables.

Note - Variable name should not be a keyword.

Declaring Variable and Assigning Values


a=10
b=20.25
c=”india”

Multiple Assignment

1. Assigning single value to multiple variables

Example:
x=y=z=50
print(x)
print (y)
print (z)

Output:

50
50
50

2.Assigning multiple values to multiple variables:

Example:

a,b,c=5,10,15

print( a )
print (b)
print (c)

Output:

5
10
15

The values will be assigned in the order in which variables appears.

Comments
Python supports two types of comments:

1) Single lined comment:

In case user wants to specify a single line comment, then comment must start with #

Eg: # This is single line comment.

2) Multi lined Comment:

Multi lined comment can be given inside triple quotes.

Example:
''' This
Is
Multiline comment'''

Example:

#single line comment


print ("Hello Python" )
'''This is
multiline comment'''

Python Keywords
Python Keywords are special reserved words which convey a special meaning to the
compiler/interpreter. Each keyword have a special meaning and a specific operation. These
keywords can't be used as variable.

True False None and as


asset def class continue break
else finally elif del except
global for if from import
raise try or return pass
nonlocal in not is lambda

Python Operators
Operators are particular symbols that are used to perform operations on operands. It returns
result that can be used in application.

Example:

4+5=9

Here 4 and 5 are Operands and (+) , (=) signs are the operators. This expression produces the
output 9.

Types of Operators
Python supports the following operators

1. Arithmetic Operators.
2. Relational Operators.
3. Logical Operators.
4. Assignment Operators.
5. Membership Operators.
6. Identity Operators.

1. Arithmetic Operators

The following table contains the arithmetic operators that are used to perform arithmetic
operations.

Operators Description

+ To perform addition
- To perform subtraction
* To perform multiplication
/ To perform division
// Perform Floor division(gives integer value after
division)
% To return remainder after division(Modulus)
** Perform exponent(raise to power)

Example:

a=10
b=3
c=a+b
d=a-b
e=a*b
f=a/b
g=a//b
h=a%b
i=a**b
print(c, d, e, f, g, h, i)
output:
13 7 30 3.3333333333333335 3 1 1000

2. Relational Operators

The following table contains the relational operators that are used to check relations.

Operators Description

< Less than


> Greater than
<= Less than or equal to
>= Greater than or equal to
== Equal to
!= Not equal to

Example:

print(10<20) # True
print( 10>20 ) # False
print(10<=10) # True
print( 20>=15) # True
print(5==6) #False
print(5!=6) # True

3. Logical Operators

The following table contains the arithmetic operators that are used to perform arithmetic
operations.

Operators Description

And Logical AND(When both conditions are true


output will be true)
Or Logical OR (If any one condition is true output
will be true)
Not Logical NOT(Compliment the condition i.e.,
reverse)

Example

a=5>4 and 3>2


print (a )
b=5>4 or 3<2
print (b)
c=not(5>4)
print (c)

Output:

True
True
False

4. Assignment Operators

The following table contains the assignment operators that are used to assign values to the
variables.

Operators Description

= Assignment a=5
/= Divide and Assign a=a/5 or a/=5
+= Add and assign a=a+5 or a+=5
-= Subtract and Assign a=a-5 or a-=5
*= Multiply and assign a=a*5 or a*=5
%= Modulus and assign a=a%5 or a%=5
**= Exponent and assign a=a**5 or a**=5
//= Floor division and assign a=a//5 or a//=5

Example:

c=10
print( c)
c+=5
print(c)
c-=5
print(c)
c*=2
print( c )
c/=2
print( c )
c%=3
print(c)
c=5
c**=2
print( c )
c//=2
print(c )

5. Membership Operators

The following table contains the membership operators.

Operators Description

In Returns true if a variable is in sequence of


another variable, else false.
not In Returns true if a variable is not in sequence of
another variable, else false.

Example:

a=10
b=20
list=[10,20,30,40,50]
if (a in list):
print ("a is in given list" )
else:
print ("a is not in given list" )

if(b not in list):


print ("b is not given in list" )
else:
print ("b is given in list" )

Output:
a is in given list
b is given in list

6. Identity Operators

The following table contains the identity operators.

Operators Description

Is Returns true if identity of two operands are


same, else false
is not Returns true if identity of two operands are not
same, else false.

Example:

a=20
b=20
if( a is b):
print ('a,b have same identity' )
else:
print ( 'a, b are different' )
b=10
if( a is not b):
print ('a,b have different identity' )
else:
print ('a,b have same identity')

Output
a,b have same identity
a,b have different identity

CONTROL STATEMENTS
Python If Statements

The Python if statement is a statement which is used to test specified condition. We can use if
statement to perform conditional operations in our Python application.

There are various types of if statements in Python.

o if statement
o if-else statement
o if – elif statement

Python If Statement Syntax

if(condition):
statements

Example

a=5
if(a<10):
print('a is less than 10')

Python If Else Statements

The If statement is used to test specified condition and if the condition is true, if block
executes, otherwise else block executes.

Python If Else Syntax

if(condition):
true statements
else:
False statements

Example

a=5
if(a<10):
print('a is less than 10 ')
else:
print('a is not less than 10 ')
Python if elif statement
In python, we can use if elif to check multiple conditions. Python provides elif keyword to
make nested If statement.

Python if elif Syntax

If statement:
Body
elif statement:
Body
else:
Body

Example

a=5
if(a<10):
print('a is less than 10 ')
elif(a>10):
print('a is greater than 10 ')
else:
print('a is equal to 10')

# if and
m=30
p=40
c=50
if(m>=35 and p>=35 and c>=35):
print('pass')
else:
print('fail')

output:
fail

# if or
a=10
b=30
if(a<20 or b<20):
print("true")
else:
print('false')

output:
true
LOOPS

For Loop

Python for loop is used to iterate the elements of a collection in the order that they appear.
This collection can be a sequence(list or string).

Python For Loop Syntax

for <variable> in <sequence>:

Python For Loop Simple Example

for i in range(10):
print(i)

output:
0123456789

for i in range (1,10):


print (i,end=’ ‘)
Output:
123456789

// step value
for i in range(1,20,2):
print(i, end=' ')

output:
1 3 5 7 9 11 13 15 17 19

// print values from 10 to 1

for i in range(10,0,-1):
print(i, end=' ')

output:
10 9 8 7 6 5 4 3 2 1

Python Nested For Loops


Loops defined within another Loop are called Nested Loops. Nested loops are used to iterate
matrix elements or to perform complex computation.

When an outer loop contains an inner loop in its body it is called Nested Looping.

Python Nested For Loop Syntax

for <expression>:
for <expression>:
Body

Example

for i in range(1,6):
for j in range(1,6):
print(j,end=' ')
print()

Output:
12345
12345
12345
12345
12345

for i in range(1,6):
for j in range(5,0,-1):
print(j,end=' ')
print()

Output:
54321
54321
54321
54321
54321

Python While Loop

In Python, while loop is used to execute number of statements or body till the specified
condition is true. Once the condition is false, the control will come out of the loop.
Python While Loop Syntax

while <expression>:
Body

Here, loop Body will execute till the expression passed is true. The Body may be a single
statement or multiple statement.

Python While Loop Example

i=1
while(i<=10):
print(i,end=' ')
i=i+1
Output:
1 2 3 4 5 6 7 8 9 10

i=10
while(i>=1):
print(i,end=' ')
i=i-1

output:
10 9 8 7 6 5 4 3 2 1

Python Break

Break statement is a jump statement which is used to transfer execution control. It breaks
the current execution and in case of inner loop, inner loop terminates immediately.

Example

for i in range(10):
if (i==4):
print ("Element found")
break
print (i)
Output:
1 2 3 Element found

Python Continue Statement


Python Continue Statement is a jump statement which is used to skip execution of current
iteration. After skipping, loop continue with next iteration.

We can use continue statement with for as well as while loop in Python.

Example

for i in range(11):
if i==5 :
continue
print(i)
Output:
1
3
5
End of Loop
Python Pass

In Python, pass keyword is used to execute nothing; it means, when we don't want to
execute code, the pass can be used to execute empty. It is same as the name refers to. It just
makes the control to pass by without executing any code. If we want to bypass any code pass
statement can be used.

Python Pass Syntax

pass

Python Pass Example

for i in [1,2,3,4,5]:
if i==3:
pass
print (i)
Output:
1
2
3
4
5

You might also like