Professional Documents
Culture Documents
Python Programming
Language
Submitted to: Submitted by:
Er. Dhiraj Srivastav Kundan Gupta
HOD [ECE Dept] 17EAIEC030
1
Development Environments
IDE
1. PyDev with Eclipse
2. Komodo
3. Emacs
4. Vim
5. TextMate
6. Gedit
7. Idle
8. PIDA (Linux)(VIM Based)
9.NotePad++ (Windows)
10.Pycharm Priyanka Pradhan 3
Web Frameworks
• Django
• Flask
• Pylons
• TurboGears
• Zope
• Grok
Priyanka Pradhan 4
Introduction
Priyanka Pradhan 5
Python features
• no compiling or linking
• rapid development cycle
• no type declarations
• simpler, shorter, more flexible
• automatic memory management
• garbage collection
• high-level data types and
operations Priyanka Pradhan 6
Contd..
• fast development
• object-oriented programming
• code structuring and reuse, C++
• embedding and extending in C
• mixed language systems
• classes, modules,
exceptions,multithreading
• "programming-in-the-large"
Priyanka Pradhan support 7
Uses of Python
• shell tools
– system admin tools, command line
programs
• extension-language work
• rapid prototyping and development
• language-based modules
– instead of special-purpose parsers
• graphical user interfaces
• database access
•• distributed programming
Internet scripting Priyanka Pradhan 10
Who Uses Python
• Google
• PBS
• NASA
• Library of Congress
• the ONION
• ...the list goes on...
Priyanka Pradhan 9
Python structure
Priyanka Pradhan 11
Hello World
Priyanka Pradhan 12
Python Overview
Priyanka Pradhan 13
The Python Interpreter
Priyanka Pradhan 14
The print Statement
•Elements separated by
commas print with a
>>> print 'hello'
space between them
hello
•A comma at the end of the
>>> print 'hello', 'there'
statement (print ‘hello’,)
hello there
will not print a newline
character
Priyanka Pradhan 15
Documentation
Priyanka Pradhan 16
Variables
Priyanka Pradhan 17
Everything is an object
• Everything means
>>> x = 7
everything, including
>>> x
functions and 7
classes (more on >>> x = 'hello'
this later!) >>> x
• Data type is a property 'hello'
>>>
of the object and not
of the variable
Priyanka Pradhan 18
Basic operations
• Assignment:
–
size = 40
–
a = b = c = 3
• Numbers
– integer, float
– complex numbers: 1j+3, abs(z)
• Strings
– 'hello world', 'it\'s hot'
– "bye world"
Priyanka Pradhan 19
String operations
Priyanka Pradhan 21
Numbers: Floating Point
Priyanka Pradhan 22
Numbers: Complex
Priyanka Pradhan 23
Numbers are immutable
x 4.5
>>> x = 4.5
>>> y = x y
>>> y += 3
x 4.5
>>> x
4.5 7.5
>>> y y
7.5
Priyanka Pradhan 24
String Literals
Priyanka Pradhan 25
String Literals: Many Kinds
• Can use single or double quotes, and three double
quotes for a multi-line string
>>> 'I am a string'
'I am a string'
>>> "So am I!"
'So am I!'
>>> s = """And me too!
though I am much longer
than the others :)"""
'And me too!\nthough I am much longer\nthan the others :)‘
>>> print s
And me too!
though I am much longer
than the others :)‘ Priyanka Pradhan
28
Substrings and Methods
•len(String) – returns the
>>> s = '012345'
number of characters in the
>>> s[3]
String
'3'
>>> s[1:4]
•str(Object) – returns a
'123'
String representation of the
>>> s[2:]
Object
'2345'
>>> s[:4] >>> len(x)
'0123' 6
>>> s[-2] >>> str(10.3)
'4' '10.3'
Priyanka Pradhan 27
String Formatting
• Similar to C’s printf
• <formatted string> % <elements to insert>
• Can usually just use %s for everything, it will
convert the object to its String representation.
>>> "One, %d, three" % 2
'One, 2, three'
>>> "%d, two, %s" % (1,3)
'1, two, 3'
>>> "%s two %s" % (1, 'three')
'1 two three'
>>>
Priyanka Pradhan 28
Do nothing
Priyanka Pradhan 29
Operators
• Arithmetic
Priyanka Pradhan 30
String Manipulation
Priyanka Pradhan 31
Logical Comparison
Priyanka Pradhan 32
Identity Comparison
Priyanka Pradhan 33
Arithmetic Comparison
Priyanka Pradhan 34
Class Declaration
Priyanka Pradhan 35
Class Attributes
Priyanka Pradhan 36
Class Methods
Priyanka Pradhan 37
Class Instantiation & Attribute
Access
Priyanka Pradhan 38
Class Inheritance
Priyanka Pradhan 39
Thank you