SlideShare a Scribd company logo
1 of 75
Download to read offline
Introduction to
By:
Morteza Zakeri
University of Arak
Fall 2014
Contents at a Glance
• What is Python?
• History and Timeline
• Python 2 and 3
• Philosophy
• Key Features
• Paradigms
• Popularity
• Getting Started
• IDLE IDE
• First Program
• Other IDEs
• Python Basics
• Variables and Data Types
• Operators
• Type Conversion
• Syntax and Structures
• Input / Output
• Identifiers
• lines
• Block and Indentation
• Quotations
• Comments
5-Jan-15 2 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Contents at a Glance
• Control Flow
• Composite Types
• Lists
• Tuples
• Ranges
• Dictionaries
• Functions
• Definitions and Calling
• Nested Functions
• First-Class Objects
• Object-Oriented Python
• Classes
• Inheritance
• Garbage Collection
• Be Pythonic!
• Summary
• References
5-Jan-15 3 of 75Intro. To Python [Morteza Zakeri – University of Arak]
What is Python?
• Python is a widely-used general purpose
(both industry and academia) high-level
Programming language.
• It combines the power of systems
languages, such as C and Java, with the
ease and rapid development of scripting
languages, such as Ruby.
5-Jan-15 4 of 75Intro. To Python [Morteza Zakeri – University of Arak]
History and Timeline
• Python Invented by Guido van Rossum
in1991 at CWI in the Netherlands.
• Python reached version 1.0 in January
1994. The major new features included in
this release were the functional
programming tools.
Van Rossum
Born: 31 January 1956 (age 58)
5-Jan-15 5 of 75Intro. To Python [Morteza Zakeri – University of Arak]
History and Timeline
• 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
5-Jan-15 6 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Python 2 and 3
• Python 2.0 was released in 2000, with many new features
added.
• Python 3.0, adjusting several aspects of the core
language, was released in 2008.
• Python 3.0 is backwards-incompatible.
• Codes written for Python 2.x may not work under 3.x!
• Python 2.x is legacy, Python 3.x is the present and future of
the language.
5-Jan-15 7 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Language Philosophy
• Beautiful is better than ugly
• Explicit is better than implicit
• Simple is better than complex
• Complex is better than complicated
• Flat is better than nested
• Sparse is better than dense
5-Jan-15 8 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Key Features
• Simple and Minimalistic
• Easy to Learn
• High-level Language
• Portable
• Interpreted
• Embeddable
• Extensive Libraries
• Free, Open Source, … and Fun!
5-Jan-15 9 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Programming Paradigms
• Python is a multi paradigm programming language.
• Imperative
• Functional
• Object-Oriented
• Aspect-Oriented
• Logic (rule base) Programming (by extension)
• …
5-Jan-15 10 of 75Intro. To Python [Morteza Zakeri – University of Arak]
5-Jan-15 11 of 75Intro. To Python [Morteza Zakeri – University of Arak]
• Top 10
Programming
Languages.
• IEEE Spectrum’s
2014 Ranking.
Popularity
Infographic:
Brandon Palacio
http://spectrum.ieee.org
5-Jan-15 12 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Getting Started
• There are three different ways to start Python
1. Interactive Interpreter
• from Unix, Linux, DOS, etc.
• Python shell begin with >>>
2. Script from the Command-line
• Install python.
• python [YourScriptFileName.py]
3. Integrated Development Environment (IDE)
• You can run Python from a graphical user interface (GUI) environment.
• All in One solution like IDLE in next slide.
5-Jan-15 13 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Getting Started
• IDLE IDE
• Download Python from
http://python.org
• Install it.
• Run it.
5-Jan-15 14 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Python Shell
5-Jan-15 15 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Simple Script with Output
5-Jan-15 16 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Other IDEs: PyDev
• PyDev is a Python
IDE for Eclipse
• http://pydev.org/
5-Jan-15 17 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Other IDEs: Visual Studio
5-Jan-15 18 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Python Basics: Objects and Variables
• In python everything is an object.
• So a variable is an object.
• A variable is name given to a memory location to store
value in the computer’s main storage.
5-Jan-15 19 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Python Basics: Objects and Variables
• Every object / Variable has three components:
1. Identity
• Object’s address in memory does not change once it has been created.
2. Type (or Class)
• A set of values and the allowable operations on those values exist for each
type.
• Type of type is type!!!
3. Value
• To bind value to a variable using assignment operator ( = ), for example:
• x = 12345
5-Jan-15 20 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Python Basics: Objects and Variables
• Python is a dynamically typed language, so:
• Use Late Binding (run time binding).
• No need to declare variable before binding a value.
• Any given variable can have its value altered at any time!
5-Jan-15 21 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Primitive Data Types
• Python has some standard types that are used to define
the operations possible on them and the storage method
for each of them.
5-Jan-15 22 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Primitive Data Types
5-Jan-15 23 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Operators
• Basic Operators
• Arithmetic (+, - , *, /, %, //, **)
• Assignment (=, +=, -=, *=, /=, %=, //= ,**= )
• Comparison (<, >, <=, >=, ==, !=)
• Logical (and, or, not)
• Notes:
• + on strings does string concatenation
• * on (string * int) repeats string
5-Jan-15 24 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Operators
5-Jan-15 25 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Type Conversion
• Python has strong typing language (unlike JavaScript)
• We need to use type converter functions:
5-Jan-15 26 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Syntax and Semantic: Simplicity
• Python syntax is simple, simple, simple!!!
• Full python grammar (BNF) is less than 120 line!
• There are less than 35 keywords in python.
5-Jan-15 27 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Syntax and Semantic: Powerfully
Simple Swap in Java: Simple Swap in Python:
5-Jan-15 28 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Input and Output
Script to calculate circle area: Output:
5-Jan-15 29 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Identifiers
• A Python identifier is a name used to identify a variable,
function, class, module, or other object.
• An identifier starts with a letter A to Z or a to z or an
underscore (_) followed by zero or more letters,
underscores, and digits (0 to 9).
• Python does not allow punctuation characters such as @,
$, and % within identifiers.
• Python is a case sensitive programming language. Thus
Var and var are two different identifiers in Python.
5-Jan-15 30 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Lines
• Single-Line Statements
• Statements in Python typically end with a new line.
• Multi-Line Statements
• character ‘’ use to denote that the line should continue.
5-Jan-15 31 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Lines
• Statements contained within the [ ], { }, or ( ) brackets do not
need to use the line continuation character. For example:
• line containing only whitespace, possibly with a comment, is
known as a blank line, and Python totally ignores it.
5-Jan-15 32 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Lines
• Multiple Statements on a Single Line
• The semicolon ( ; ) allows multiple statements on the single line.
• Multiple Statement Groups called Suites
• Groups of individual statements making up a single code block
are called suites.
• Compound or complex statements, such as “if”, “while”, “def”,
and “class”, are those which require a header line and a suite.
5-Jan-15 33 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Blocks and Indentations
• Blocks begin with colon mark ( : )
• Nested blocks are allowed.
• Line Indentation use to determine blocks scope!
• The number of spaces in the indentation is variable, but all
statements within the block must be indented the same amount
• pass keyword use to fill empty or not implementation
blocks body.
• pass ≡ do nothing
5-Jan-15 34 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Quotations
• Python accepts single ('), double (") and triple (''' or """)
quotes to denote string literals, as long as the same type
of quote starts and ends the string.
• The triple quotes can be used to span the string across
multiple lines.
5-Jan-15 35 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Comments
• A hash sign (#) that is not inside a string literal begins a
comment.
• All characters after the # and up to the physical line end
are part of the comment, and the Python interpreter
ignores them.
5-Jan-15 36 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Control Flow: Conditions
• Like other languages, Python has if and else statements
• Python’s “else-if” is spelled elif
5-Jan-15 37 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Control Flow: Conditions
• Python has an easy to use if-syntax for setting the value of
a variable!
5-Jan-15 38 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Truth and Falsity Value Testing
• Any object can be tested for truth value, for use in a
condition.
• False:
1. None (≡ 𝑛𝑢𝑙𝑙)
2. False (Python >= 2.2.1)
3. Zero of any numeric type, e.g., 0, 0.0, 0j
4. Any empty sequence or dictionary, e.g., ‘ ‘, ( ), [ ], { }
• True:
• Everything else
5-Jan-15 39 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Control Flow: Loops
• While loop
• The while loop continues to execute the same body of code until
the conditional statement is no longer True.
• We can use break and continue inside the loops
5-Jan-15 40 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Control Flow: Loops
• For loop
• The for loop in Python is much simpler that other C-like
languages.
• We can use range() function to produce a list of numbers.
5-Jan-15 41 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Sequence Types
• There are three basic sequence types:
• lists
• Tuples
• range objects
• Additional sequence types include:
• Strings (str)
• Binary Data (bytes, bytearray, memoryview)
5-Jan-15 42 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Sequence Types
• Sequence types are very like together.
• All of them consist of iterables objects.
• There are some difference:
• Lists are mutable, heterogeneous.
• Tuple are immutable, heterogeneous.
• Ranges are immutable, homogeneous.
• String are immutable, homogeneous.
• Immutable ≡ 𝐶𝑎𝑛′
𝑡 𝑢𝑠𝑒 𝑎𝑠 𝑙 − 𝑣𝑎𝑙𝑢𝑒
5-Jan-15 43 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Lists
• Lists are similar to arrays in C. One difference between
them is that all the items belonging to a list can be of
different data type.
• [] – an empty list.
• [6] – an one-element list.
• [5, 1+2j, ’hello’] - a 3-element list (heterogeneous).
• [[1,2], [3,4], [5,6]] - a list of lists.
5-Jan-15 44 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Lists
• Lists may be constructed in several ways:
• Using a pair of square brackets to denote the empty list:
• L = []
• Using square brackets, separating items with commas:
• L = [a] or L = [a, b, c]
• Using a list comprehension:
• L = [x for x in iterable]
• Using the type constructor:
• L = list() or L = list(iterable)
5-Jan-15 45 of 75Intro. To Python [Morteza Zakeri – University of Arak]
list comprehension
• A compact way to process all or part of the elements in a
sequence and return a list with the results.
• result = ['{:#04x}'.format(x) for x in range(256) if x % 2 == 0]
• generates a list of strings containing even hex numbers (0x..) in
the range from 0 to 255.
• The if clause is optional. If omitted, all elements in range(256) are
processed.
5-Jan-15 46 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Tuples
• A tuple is another sequence data type that is similar to the
list.
• A tuple consists of a number of values separated by
commas.
• The main differences between lists and tuples are:
• Lists are enclosed in brackets ( [ ] ), and their elements and size
can be changed, while tuples are enclosed in parentheses ( ( ) )
and cannot be updated.
• Tuples can be thought of as read-only lists.
5-Jan-15 47 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Tuples
• Tuples may be constructed in a number of ways:
• Using a pair of parentheses to denote the empty tuple:
• T = ()
• Using a trailing comma for a singleton tuple:
• T= 1, or T = (1,)
• Separating items with commas:
• a, b, c or (a, b, c)
• Using the tuple() built-in:
• T = tuple() or T = tuple(iterable)
5-Jan-15 48 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Ranges
• The range type represents an immutable sequence of
numbers and is commonly used for looping a specific
number of times in for loops.
• The advantage of the range type over a regular list or
tuple is that a range object will always take the same
(small) amount of memory, no matter the size of the range
it represents (as it only stores the start, stop and step
values, calculating individual items and subranges as
needed).
5-Jan-15 49 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Ranges
5-Jan-15 50 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Common Sequence Operations
5-Jan-15 51 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Dictionaries
• Python's dictionaries are hash table type. They work like
associative arrays in Perl and consist of key-value pairs.
• Keys can be almost any Python type, but are usually numbers
or strings. Values, on the other hand, can be any arbitrary
Python object.
• Dictionaries are enclosed by curly braces ( { } ) and values can
be assigned and accessed using square braces ( [] ).
• Dictionaries have no concept of order among elements. It is
incorrect to say that the elements are “out of order”; they are
simply unordered.
5-Jan-15 52 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Dictionaries
5-Jan-15 53 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Functions
• Function objects are created by function definitions. The
only operation on a function object is to call it:
• function-name(argument-list).
• There are really two flavors of function objects:
• built-in functions
• user-defined functions.
• Both support the same operation (to call the function), but
the implementation is different, hence the different object
types.
5-Jan-15 54 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Methods
• Method is a function defined in a class namespace.
• There are two flavors:
• built-in methods (such as append() on lists)
• class instance methods.
• Built-in methods are described with the types that support
them.
5-Jan-15 55 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Define Functions
• Function blocks begin with the keyword def followed by the
function name and parentheses.
• The first statement of a function can be an optional statement
- the documentation string of the function or docstring.
• The code block within every function starts with a colon ( : )
and is indented.
• The statement return [expression] exits a function, optionally
passing back an expression to the caller. A return statement
with no arguments is the same as return None.
5-Jan-15 56 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Define Functions
5-Jan-15 57 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Arguments Passing
• Pass by reference vs value
• All parameters (arguments) in the Python language are passed
by reference.
• If you change what a parameter refers to within a function, the
change also reflects back in the calling function.
• If you assigned new value to parameter by assign operation (=),
new reference will be created (call by value!!!)
• So python provide two semantic by one syntax in function
calling!!!
5-Jan-15 58 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Arguments Passing
5-Jan-15 59 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Arguments Passing
5-Jan-15 60 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Arguments Types
• You can call a function by using the following types of
formal arguments:
• Required arguments
• Keyword arguments
• Default arguments
• Variable-length arguments
5-Jan-15 61 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Arguments Types
5-Jan-15 62 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Nested Functions
• Function scopes (and class scopes) can be nested.
• Python using static scope.
• Inner function can’t access to variables reference exist in
outer function but R-Value allowed!
• nonlocal keyword use to access outer variables so
dynamic scope will provide!!!
5-Jan-15 63 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Nested Functions
5-Jan-15 64 of 75Intro. To Python [Morteza Zakeri – University of Arak]
First-Class Objects
• Almost everything (including functions, classes, etc) in
Python is a first-class object!
5-Jan-15 65 of 75Intro. To Python [Morteza Zakeri – University of Arak]
First-Class Objects
5-Jan-15 66 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Object-Oriented Python
• Python support object-oriented (class and objects)
• Python support multiple inheritance
5-Jan-15 67 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Object-Oriented Python
5-Jan-15 68 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Destroying Objects (Garbage Collection)
• Allocating and freeing memory is not your problem!
• Python uses reference counting.
• An object's reference count increases when it's assigned a
new name or placed in a container (list, tuple, etc). The
object's reference count decreases when it's deleted with
del.
• When an object's reference count reaches zero, Python
collects it automatically.
5-Jan-15 69 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Be Pythonic!
5-Jan-15 70 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Alternative Python Implementations
• CPython: Traditional implementation of Python that we
used in this introduction.
• IronPython: Python running on .NET
• Jython: Python running on the Java Virtual Machine (JVM)
• PyPy: A fast python implementation with a just in-time (JIT)
compiler.
• More:
• https://www.python.org/download/alternatives
5-Jan-15 71 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Famous Apps. written in python
• Dropbox: A web-based file hosting service
• BitTorrent: original client, along with several derivatives.
• Ubuntu Software Center: A graphical package manager,
installed by default in Ubuntu 9.10 and higher.
• More:
• http://en.wikipedia.org/wiki/List_of_Python_software
5-Jan-15 72 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Summary
• Python is
• High-Level
• Multi-Paradigm
• and has
• Dynamic Type
• Strong Type
• and use
• Call by Reference(and value)
• Static (and Dynamic) Scope
5-Jan-15 73 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Reference
1. Python Official Website
• http://python.org/
2. Python 3 Documentation
• http://docs.python.org/3/
3. Python Tutorials
• http://www.tutorialspoint.com/python/
4. Learning Python, Fifth Edition
• Mark Lutz, Published by O’Reilly Media, Inc. 2013
5-Jan-15 74 of 75Intro. To Python [Morteza Zakeri – University of Arak]
Thank you for your attention.
Slides will available on:
• http://micropedia.ir/python

More Related Content

What's hot

Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Pedro Rodrigues
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to pythonAgung Wahyudi
 
Python Basics | Python Tutorial | Edureka
Python Basics | Python Tutorial | EdurekaPython Basics | Python Tutorial | Edureka
Python Basics | Python Tutorial | EdurekaEdureka!
 
Introduction To Python | Edureka
Introduction To Python | EdurekaIntroduction To Python | Edureka
Introduction To Python | EdurekaEdureka!
 
Python Programming Language
Python Programming LanguagePython Programming Language
Python Programming LanguageDr.YNM
 
Python Tutorial | Python Tutorial for Beginners | Python Training | Edureka
Python Tutorial | Python Tutorial for Beginners | Python Training | EdurekaPython Tutorial | Python Tutorial for Beginners | Python Training | Edureka
Python Tutorial | Python Tutorial for Beginners | Python Training | EdurekaEdureka!
 
Python presentation by Monu Sharma
Python presentation by Monu SharmaPython presentation by Monu Sharma
Python presentation by Monu SharmaMayank Sharma
 
Learning Python with PyCharm EDU
Learning Python with PyCharm EDU Learning Python with PyCharm EDU
Learning Python with PyCharm EDU Sergey Aganezov
 
POWER OF PYTHON PROGRAMMING LANGUAGE
POWER OF PYTHON PROGRAMMING LANGUAGE POWER OF PYTHON PROGRAMMING LANGUAGE
POWER OF PYTHON PROGRAMMING LANGUAGE teachersduniya.com
 
Fundamentals of python
Fundamentals of pythonFundamentals of python
Fundamentals of pythonBijuAugustian
 
Python Sequence | Python Lists | Python Sets & Dictionary | Python Strings | ...
Python Sequence | Python Lists | Python Sets & Dictionary | Python Strings | ...Python Sequence | Python Lists | Python Sets & Dictionary | Python Strings | ...
Python Sequence | Python Lists | Python Sets & Dictionary | Python Strings | ...Edureka!
 
What is Python? | Edureka
What is Python? | EdurekaWhat is Python? | Edureka
What is Python? | EdurekaEdureka!
 
Introduction To Python
Introduction To PythonIntroduction To Python
Introduction To PythonVanessa Rene
 

What's hot (20)

Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Python ppt
Python pptPython ppt
Python ppt
 
Python Basics | Python Tutorial | Edureka
Python Basics | Python Tutorial | EdurekaPython Basics | Python Tutorial | Edureka
Python Basics | Python Tutorial | Edureka
 
Python
PythonPython
Python
 
Introduction To Python | Edureka
Introduction To Python | EdurekaIntroduction To Python | Edureka
Introduction To Python | Edureka
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Python Programming Language
Python Programming LanguagePython Programming Language
Python Programming Language
 
Python Basics
Python BasicsPython Basics
Python Basics
 
Python programming
Python programmingPython programming
Python programming
 
Python Tutorial | Python Tutorial for Beginners | Python Training | Edureka
Python Tutorial | Python Tutorial for Beginners | Python Training | EdurekaPython Tutorial | Python Tutorial for Beginners | Python Training | Edureka
Python Tutorial | Python Tutorial for Beginners | Python Training | Edureka
 
Python presentation by Monu Sharma
Python presentation by Monu SharmaPython presentation by Monu Sharma
Python presentation by Monu Sharma
 
Learning Python with PyCharm EDU
Learning Python with PyCharm EDU Learning Python with PyCharm EDU
Learning Python with PyCharm EDU
 
POWER OF PYTHON PROGRAMMING LANGUAGE
POWER OF PYTHON PROGRAMMING LANGUAGE POWER OF PYTHON PROGRAMMING LANGUAGE
POWER OF PYTHON PROGRAMMING LANGUAGE
 
Fundamentals of python
Fundamentals of pythonFundamentals of python
Fundamentals of python
 
Python Sequence | Python Lists | Python Sets & Dictionary | Python Strings | ...
Python Sequence | Python Lists | Python Sets & Dictionary | Python Strings | ...Python Sequence | Python Lists | Python Sets & Dictionary | Python Strings | ...
Python Sequence | Python Lists | Python Sets & Dictionary | Python Strings | ...
 
Python by Rj
Python by RjPython by Rj
Python by Rj
 
What is Python? | Edureka
What is Python? | EdurekaWhat is Python? | Edureka
What is Python? | Edureka
 
Introduction To Python
Introduction To PythonIntroduction To Python
Introduction To Python
 
Python
PythonPython
Python
 

Similar to An Introduction to Python Programming

Introduction about Python by JanBask Training
Introduction about Python by JanBask TrainingIntroduction about Python by JanBask Training
Introduction about Python by JanBask TrainingJanBask Training
 
web programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Malothweb programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh MalothBhavsingh Maloth
 
What is Python?
What is Python?What is Python?
What is Python?PranavSB
 
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptxsangeeta borde
 
Tutorial on-python-programming
Tutorial on-python-programmingTutorial on-python-programming
Tutorial on-python-programmingChetan Giridhar
 
PYTHON PROGRAMMING.pptx
PYTHON PROGRAMMING.pptxPYTHON PROGRAMMING.pptx
PYTHON PROGRAMMING.pptxswarna627082
 
Note for Java Programming////////////////
Note for Java Programming////////////////Note for Java Programming////////////////
Note for Java Programming////////////////MeghaKulkarni27
 
Python for katana
Python for katanaPython for katana
Python for katanakedar nath
 
Fundamentals of Python Programming
Fundamentals of Python ProgrammingFundamentals of Python Programming
Fundamentals of Python ProgrammingKamal Acharya
 
Introduction to Analytics with Azure Notebooks and Python
Introduction to Analytics with Azure Notebooks and PythonIntroduction to Analytics with Azure Notebooks and Python
Introduction to Analytics with Azure Notebooks and PythonJen Stirrup
 
Lecture1_introduction to python.pptx
Lecture1_introduction to python.pptxLecture1_introduction to python.pptx
Lecture1_introduction to python.pptxMohammedAlYemeni1
 

Similar to An Introduction to Python Programming (20)

Introduction about Python by JanBask Training
Introduction about Python by JanBask TrainingIntroduction about Python by JanBask Training
Introduction about Python by JanBask Training
 
Python Tutorial for Beginner
Python Tutorial for BeginnerPython Tutorial for Beginner
Python Tutorial for Beginner
 
web programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Malothweb programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Maloth
 
Data wrangling week2
Data wrangling week2Data wrangling week2
Data wrangling week2
 
intro to python.pptx
intro to python.pptxintro to python.pptx
intro to python.pptx
 
What is Python?
What is Python?What is Python?
What is Python?
 
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
 
Tutorial on-python-programming
Tutorial on-python-programmingTutorial on-python-programming
Tutorial on-python-programming
 
Python Programming 1.pptx
Python Programming 1.pptxPython Programming 1.pptx
Python Programming 1.pptx
 
Class_X_PYTHON_J.pdf
Class_X_PYTHON_J.pdfClass_X_PYTHON_J.pdf
Class_X_PYTHON_J.pdf
 
PYTHON PROGRAMMING.pptx
PYTHON PROGRAMMING.pptxPYTHON PROGRAMMING.pptx
PYTHON PROGRAMMING.pptx
 
Python Demo.pptx
Python Demo.pptxPython Demo.pptx
Python Demo.pptx
 
Demo learn python
Demo learn pythonDemo learn python
Demo learn python
 
Python Programming
Python ProgrammingPython Programming
Python Programming
 
Python Demo.pptx
Python Demo.pptxPython Demo.pptx
Python Demo.pptx
 
Note for Java Programming////////////////
Note for Java Programming////////////////Note for Java Programming////////////////
Note for Java Programming////////////////
 
Python for katana
Python for katanaPython for katana
Python for katana
 
Fundamentals of Python Programming
Fundamentals of Python ProgrammingFundamentals of Python Programming
Fundamentals of Python Programming
 
Introduction to Analytics with Azure Notebooks and Python
Introduction to Analytics with Azure Notebooks and PythonIntroduction to Analytics with Azure Notebooks and Python
Introduction to Analytics with Azure Notebooks and Python
 
Lecture1_introduction to python.pptx
Lecture1_introduction to python.pptxLecture1_introduction to python.pptx
Lecture1_introduction to python.pptx
 

More from Morteza Zakeri

Antlr part3 getting_started_in_c_sharp
Antlr part3 getting_started_in_c_sharpAntlr part3 getting_started_in_c_sharp
Antlr part3 getting_started_in_c_sharpMorteza Zakeri
 
Antlr part1 introduction
Antlr part1 introductionAntlr part1 introduction
Antlr part1 introductionMorteza Zakeri
 
Antlr part2 getting_started_in_java
Antlr part2 getting_started_in_javaAntlr part2 getting_started_in_java
Antlr part2 getting_started_in_javaMorteza Zakeri
 
2-requirements-modelling
2-requirements-modelling2-requirements-modelling
2-requirements-modellingMorteza Zakeri
 
1-requirements-elicitation
1-requirements-elicitation1-requirements-elicitation
1-requirements-elicitationMorteza Zakeri
 
Analysis of Social Phenomena Using Machine Learning Techniques: A Mixed Resea...
Analysis of Social Phenomena Using Machine Learning Techniques: A Mixed Resea...Analysis of Social Phenomena Using Machine Learning Techniques: A Mixed Resea...
Analysis of Social Phenomena Using Machine Learning Techniques: A Mixed Resea...Morteza Zakeri
 
Internet of Things: Middle-ware Platforms, Security, and Intrusion Detection
Internet of Things: Middle-ware Platforms, Security, and Intrusion DetectionInternet of Things: Middle-ware Platforms, Security, and Intrusion Detection
Internet of Things: Middle-ware Platforms, Security, and Intrusion DetectionMorteza Zakeri
 
Community Detection with Genetic Algorithm
Community Detection with Genetic AlgorithmCommunity Detection with Genetic Algorithm
Community Detection with Genetic AlgorithmMorteza Zakeri
 
SpotifyX Architectural Review
SpotifyX Architectural ReviewSpotifyX Architectural Review
SpotifyX Architectural ReviewMorteza Zakeri
 
An overview of anomaly detection techniques
An overview of anomaly detection techniquesAn overview of anomaly detection techniques
An overview of anomaly detection techniquesMorteza Zakeri
 
SQLite and object-relational mapping in Java
SQLite and object-relational mapping in JavaSQLite and object-relational mapping in Java
SQLite and object-relational mapping in JavaMorteza Zakeri
 
Apache Mesos: Architecture, Design and Code Review
Apache Mesos: Architecture, Design and Code ReviewApache Mesos: Architecture, Design and Code Review
Apache Mesos: Architecture, Design and Code ReviewMorteza Zakeri
 
یادگیری توالی به توالی با شبکه های عصبی
یادگیری توالی به توالی با شبکه های عصبییادگیری توالی به توالی با شبکه های عصبی
یادگیری توالی به توالی با شبکه های عصبیMorteza Zakeri
 

More from Morteza Zakeri (20)

Antlr part3 getting_started_in_c_sharp
Antlr part3 getting_started_in_c_sharpAntlr part3 getting_started_in_c_sharp
Antlr part3 getting_started_in_c_sharp
 
Antlr part1 introduction
Antlr part1 introductionAntlr part1 introduction
Antlr part1 introduction
 
Antlr part2 getting_started_in_java
Antlr part2 getting_started_in_javaAntlr part2 getting_started_in_java
Antlr part2 getting_started_in_java
 
9-roslyn-guidelines
9-roslyn-guidelines9-roslyn-guidelines
9-roslyn-guidelines
 
7-clean-code
7-clean-code7-clean-code
7-clean-code
 
8-bad-smells
8-bad-smells8-bad-smells
8-bad-smells
 
6-TDD
6-TDD6-TDD
6-TDD
 
3-use-casemodelling
3-use-casemodelling3-use-casemodelling
3-use-casemodelling
 
5-modular-design
5-modular-design5-modular-design
5-modular-design
 
4-architectural-views
4-architectural-views4-architectural-views
4-architectural-views
 
2-requirements-modelling
2-requirements-modelling2-requirements-modelling
2-requirements-modelling
 
1-requirements-elicitation
1-requirements-elicitation1-requirements-elicitation
1-requirements-elicitation
 
Analysis of Social Phenomena Using Machine Learning Techniques: A Mixed Resea...
Analysis of Social Phenomena Using Machine Learning Techniques: A Mixed Resea...Analysis of Social Phenomena Using Machine Learning Techniques: A Mixed Resea...
Analysis of Social Phenomena Using Machine Learning Techniques: A Mixed Resea...
 
Internet of Things: Middle-ware Platforms, Security, and Intrusion Detection
Internet of Things: Middle-ware Platforms, Security, and Intrusion DetectionInternet of Things: Middle-ware Platforms, Security, and Intrusion Detection
Internet of Things: Middle-ware Platforms, Security, and Intrusion Detection
 
Community Detection with Genetic Algorithm
Community Detection with Genetic AlgorithmCommunity Detection with Genetic Algorithm
Community Detection with Genetic Algorithm
 
SpotifyX Architectural Review
SpotifyX Architectural ReviewSpotifyX Architectural Review
SpotifyX Architectural Review
 
An overview of anomaly detection techniques
An overview of anomaly detection techniquesAn overview of anomaly detection techniques
An overview of anomaly detection techniques
 
SQLite and object-relational mapping in Java
SQLite and object-relational mapping in JavaSQLite and object-relational mapping in Java
SQLite and object-relational mapping in Java
 
Apache Mesos: Architecture, Design and Code Review
Apache Mesos: Architecture, Design and Code ReviewApache Mesos: Architecture, Design and Code Review
Apache Mesos: Architecture, Design and Code Review
 
یادگیری توالی به توالی با شبکه های عصبی
یادگیری توالی به توالی با شبکه های عصبییادگیری توالی به توالی با شبکه های عصبی
یادگیری توالی به توالی با شبکه های عصبی
 

Recently uploaded

Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringmulugeta48
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoordharasingh5698
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdfSuman Jyoti
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 

Recently uploaded (20)

Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 

An Introduction to Python Programming

  • 2. Contents at a Glance • What is Python? • History and Timeline • Python 2 and 3 • Philosophy • Key Features • Paradigms • Popularity • Getting Started • IDLE IDE • First Program • Other IDEs • Python Basics • Variables and Data Types • Operators • Type Conversion • Syntax and Structures • Input / Output • Identifiers • lines • Block and Indentation • Quotations • Comments 5-Jan-15 2 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 3. Contents at a Glance • Control Flow • Composite Types • Lists • Tuples • Ranges • Dictionaries • Functions • Definitions and Calling • Nested Functions • First-Class Objects • Object-Oriented Python • Classes • Inheritance • Garbage Collection • Be Pythonic! • Summary • References 5-Jan-15 3 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 4. What is Python? • Python is a widely-used general purpose (both industry and academia) high-level Programming language. • It combines the power of systems languages, such as C and Java, with the ease and rapid development of scripting languages, such as Ruby. 5-Jan-15 4 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 5. History and Timeline • Python Invented by Guido van Rossum in1991 at CWI in the Netherlands. • Python reached version 1.0 in January 1994. The major new features included in this release were the functional programming tools. Van Rossum Born: 31 January 1956 (age 58) 5-Jan-15 5 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 6. History and Timeline • 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 5-Jan-15 6 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 7. Python 2 and 3 • Python 2.0 was released in 2000, with many new features added. • Python 3.0, adjusting several aspects of the core language, was released in 2008. • Python 3.0 is backwards-incompatible. • Codes written for Python 2.x may not work under 3.x! • Python 2.x is legacy, Python 3.x is the present and future of the language. 5-Jan-15 7 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 8. Language Philosophy • Beautiful is better than ugly • Explicit is better than implicit • Simple is better than complex • Complex is better than complicated • Flat is better than nested • Sparse is better than dense 5-Jan-15 8 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 9. Key Features • Simple and Minimalistic • Easy to Learn • High-level Language • Portable • Interpreted • Embeddable • Extensive Libraries • Free, Open Source, … and Fun! 5-Jan-15 9 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 10. Programming Paradigms • Python is a multi paradigm programming language. • Imperative • Functional • Object-Oriented • Aspect-Oriented • Logic (rule base) Programming (by extension) • … 5-Jan-15 10 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 11. 5-Jan-15 11 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 12. • Top 10 Programming Languages. • IEEE Spectrum’s 2014 Ranking. Popularity Infographic: Brandon Palacio http://spectrum.ieee.org 5-Jan-15 12 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 13. Getting Started • There are three different ways to start Python 1. Interactive Interpreter • from Unix, Linux, DOS, etc. • Python shell begin with >>> 2. Script from the Command-line • Install python. • python [YourScriptFileName.py] 3. Integrated Development Environment (IDE) • You can run Python from a graphical user interface (GUI) environment. • All in One solution like IDLE in next slide. 5-Jan-15 13 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 14. Getting Started • IDLE IDE • Download Python from http://python.org • Install it. • Run it. 5-Jan-15 14 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 15. Python Shell 5-Jan-15 15 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 16. Simple Script with Output 5-Jan-15 16 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 17. Other IDEs: PyDev • PyDev is a Python IDE for Eclipse • http://pydev.org/ 5-Jan-15 17 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 18. Other IDEs: Visual Studio 5-Jan-15 18 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 19. Python Basics: Objects and Variables • In python everything is an object. • So a variable is an object. • A variable is name given to a memory location to store value in the computer’s main storage. 5-Jan-15 19 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 20. Python Basics: Objects and Variables • Every object / Variable has three components: 1. Identity • Object’s address in memory does not change once it has been created. 2. Type (or Class) • A set of values and the allowable operations on those values exist for each type. • Type of type is type!!! 3. Value • To bind value to a variable using assignment operator ( = ), for example: • x = 12345 5-Jan-15 20 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 21. Python Basics: Objects and Variables • Python is a dynamically typed language, so: • Use Late Binding (run time binding). • No need to declare variable before binding a value. • Any given variable can have its value altered at any time! 5-Jan-15 21 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 22. Primitive Data Types • Python has some standard types that are used to define the operations possible on them and the storage method for each of them. 5-Jan-15 22 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 23. Primitive Data Types 5-Jan-15 23 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 24. Operators • Basic Operators • Arithmetic (+, - , *, /, %, //, **) • Assignment (=, +=, -=, *=, /=, %=, //= ,**= ) • Comparison (<, >, <=, >=, ==, !=) • Logical (and, or, not) • Notes: • + on strings does string concatenation • * on (string * int) repeats string 5-Jan-15 24 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 25. Operators 5-Jan-15 25 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 26. Type Conversion • Python has strong typing language (unlike JavaScript) • We need to use type converter functions: 5-Jan-15 26 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 27. Syntax and Semantic: Simplicity • Python syntax is simple, simple, simple!!! • Full python grammar (BNF) is less than 120 line! • There are less than 35 keywords in python. 5-Jan-15 27 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 28. Syntax and Semantic: Powerfully Simple Swap in Java: Simple Swap in Python: 5-Jan-15 28 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 29. Input and Output Script to calculate circle area: Output: 5-Jan-15 29 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 30. Identifiers • A Python identifier is a name used to identify a variable, function, class, module, or other object. • An identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero or more letters, underscores, and digits (0 to 9). • Python does not allow punctuation characters such as @, $, and % within identifiers. • Python is a case sensitive programming language. Thus Var and var are two different identifiers in Python. 5-Jan-15 30 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 31. Lines • Single-Line Statements • Statements in Python typically end with a new line. • Multi-Line Statements • character ‘’ use to denote that the line should continue. 5-Jan-15 31 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 32. Lines • Statements contained within the [ ], { }, or ( ) brackets do not need to use the line continuation character. For example: • line containing only whitespace, possibly with a comment, is known as a blank line, and Python totally ignores it. 5-Jan-15 32 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 33. Lines • Multiple Statements on a Single Line • The semicolon ( ; ) allows multiple statements on the single line. • Multiple Statement Groups called Suites • Groups of individual statements making up a single code block are called suites. • Compound or complex statements, such as “if”, “while”, “def”, and “class”, are those which require a header line and a suite. 5-Jan-15 33 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 34. Blocks and Indentations • Blocks begin with colon mark ( : ) • Nested blocks are allowed. • Line Indentation use to determine blocks scope! • The number of spaces in the indentation is variable, but all statements within the block must be indented the same amount • pass keyword use to fill empty or not implementation blocks body. • pass ≡ do nothing 5-Jan-15 34 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 35. Quotations • Python accepts single ('), double (") and triple (''' or """) quotes to denote string literals, as long as the same type of quote starts and ends the string. • The triple quotes can be used to span the string across multiple lines. 5-Jan-15 35 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 36. Comments • A hash sign (#) that is not inside a string literal begins a comment. • All characters after the # and up to the physical line end are part of the comment, and the Python interpreter ignores them. 5-Jan-15 36 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 37. Control Flow: Conditions • Like other languages, Python has if and else statements • Python’s “else-if” is spelled elif 5-Jan-15 37 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 38. Control Flow: Conditions • Python has an easy to use if-syntax for setting the value of a variable! 5-Jan-15 38 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 39. Truth and Falsity Value Testing • Any object can be tested for truth value, for use in a condition. • False: 1. None (≡ 𝑛𝑢𝑙𝑙) 2. False (Python >= 2.2.1) 3. Zero of any numeric type, e.g., 0, 0.0, 0j 4. Any empty sequence or dictionary, e.g., ‘ ‘, ( ), [ ], { } • True: • Everything else 5-Jan-15 39 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 40. Control Flow: Loops • While loop • The while loop continues to execute the same body of code until the conditional statement is no longer True. • We can use break and continue inside the loops 5-Jan-15 40 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 41. Control Flow: Loops • For loop • The for loop in Python is much simpler that other C-like languages. • We can use range() function to produce a list of numbers. 5-Jan-15 41 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 42. Sequence Types • There are three basic sequence types: • lists • Tuples • range objects • Additional sequence types include: • Strings (str) • Binary Data (bytes, bytearray, memoryview) 5-Jan-15 42 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 43. Sequence Types • Sequence types are very like together. • All of them consist of iterables objects. • There are some difference: • Lists are mutable, heterogeneous. • Tuple are immutable, heterogeneous. • Ranges are immutable, homogeneous. • String are immutable, homogeneous. • Immutable ≡ 𝐶𝑎𝑛′ 𝑡 𝑢𝑠𝑒 𝑎𝑠 𝑙 − 𝑣𝑎𝑙𝑢𝑒 5-Jan-15 43 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 44. Lists • Lists are similar to arrays in C. One difference between them is that all the items belonging to a list can be of different data type. • [] – an empty list. • [6] – an one-element list. • [5, 1+2j, ’hello’] - a 3-element list (heterogeneous). • [[1,2], [3,4], [5,6]] - a list of lists. 5-Jan-15 44 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 45. Lists • Lists may be constructed in several ways: • Using a pair of square brackets to denote the empty list: • L = [] • Using square brackets, separating items with commas: • L = [a] or L = [a, b, c] • Using a list comprehension: • L = [x for x in iterable] • Using the type constructor: • L = list() or L = list(iterable) 5-Jan-15 45 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 46. list comprehension • A compact way to process all or part of the elements in a sequence and return a list with the results. • result = ['{:#04x}'.format(x) for x in range(256) if x % 2 == 0] • generates a list of strings containing even hex numbers (0x..) in the range from 0 to 255. • The if clause is optional. If omitted, all elements in range(256) are processed. 5-Jan-15 46 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 47. Tuples • A tuple is another sequence data type that is similar to the list. • A tuple consists of a number of values separated by commas. • The main differences between lists and tuples are: • Lists are enclosed in brackets ( [ ] ), and their elements and size can be changed, while tuples are enclosed in parentheses ( ( ) ) and cannot be updated. • Tuples can be thought of as read-only lists. 5-Jan-15 47 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 48. Tuples • Tuples may be constructed in a number of ways: • Using a pair of parentheses to denote the empty tuple: • T = () • Using a trailing comma for a singleton tuple: • T= 1, or T = (1,) • Separating items with commas: • a, b, c or (a, b, c) • Using the tuple() built-in: • T = tuple() or T = tuple(iterable) 5-Jan-15 48 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 49. Ranges • The range type represents an immutable sequence of numbers and is commonly used for looping a specific number of times in for loops. • The advantage of the range type over a regular list or tuple is that a range object will always take the same (small) amount of memory, no matter the size of the range it represents (as it only stores the start, stop and step values, calculating individual items and subranges as needed). 5-Jan-15 49 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 50. Ranges 5-Jan-15 50 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 51. Common Sequence Operations 5-Jan-15 51 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 52. Dictionaries • Python's dictionaries are hash table type. They work like associative arrays in Perl and consist of key-value pairs. • Keys can be almost any Python type, but are usually numbers or strings. Values, on the other hand, can be any arbitrary Python object. • Dictionaries are enclosed by curly braces ( { } ) and values can be assigned and accessed using square braces ( [] ). • Dictionaries have no concept of order among elements. It is incorrect to say that the elements are “out of order”; they are simply unordered. 5-Jan-15 52 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 53. Dictionaries 5-Jan-15 53 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 54. Functions • Function objects are created by function definitions. The only operation on a function object is to call it: • function-name(argument-list). • There are really two flavors of function objects: • built-in functions • user-defined functions. • Both support the same operation (to call the function), but the implementation is different, hence the different object types. 5-Jan-15 54 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 55. Methods • Method is a function defined in a class namespace. • There are two flavors: • built-in methods (such as append() on lists) • class instance methods. • Built-in methods are described with the types that support them. 5-Jan-15 55 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 56. Define Functions • Function blocks begin with the keyword def followed by the function name and parentheses. • The first statement of a function can be an optional statement - the documentation string of the function or docstring. • The code block within every function starts with a colon ( : ) and is indented. • The statement return [expression] exits a function, optionally passing back an expression to the caller. A return statement with no arguments is the same as return None. 5-Jan-15 56 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 57. Define Functions 5-Jan-15 57 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 58. Arguments Passing • Pass by reference vs value • All parameters (arguments) in the Python language are passed by reference. • If you change what a parameter refers to within a function, the change also reflects back in the calling function. • If you assigned new value to parameter by assign operation (=), new reference will be created (call by value!!!) • So python provide two semantic by one syntax in function calling!!! 5-Jan-15 58 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 59. Arguments Passing 5-Jan-15 59 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 60. Arguments Passing 5-Jan-15 60 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 61. Arguments Types • You can call a function by using the following types of formal arguments: • Required arguments • Keyword arguments • Default arguments • Variable-length arguments 5-Jan-15 61 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 62. Arguments Types 5-Jan-15 62 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 63. Nested Functions • Function scopes (and class scopes) can be nested. • Python using static scope. • Inner function can’t access to variables reference exist in outer function but R-Value allowed! • nonlocal keyword use to access outer variables so dynamic scope will provide!!! 5-Jan-15 63 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 64. Nested Functions 5-Jan-15 64 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 65. First-Class Objects • Almost everything (including functions, classes, etc) in Python is a first-class object! 5-Jan-15 65 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 66. First-Class Objects 5-Jan-15 66 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 67. Object-Oriented Python • Python support object-oriented (class and objects) • Python support multiple inheritance 5-Jan-15 67 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 68. Object-Oriented Python 5-Jan-15 68 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 69. Destroying Objects (Garbage Collection) • Allocating and freeing memory is not your problem! • Python uses reference counting. • An object's reference count increases when it's assigned a new name or placed in a container (list, tuple, etc). The object's reference count decreases when it's deleted with del. • When an object's reference count reaches zero, Python collects it automatically. 5-Jan-15 69 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 70. Be Pythonic! 5-Jan-15 70 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 71. Alternative Python Implementations • CPython: Traditional implementation of Python that we used in this introduction. • IronPython: Python running on .NET • Jython: Python running on the Java Virtual Machine (JVM) • PyPy: A fast python implementation with a just in-time (JIT) compiler. • More: • https://www.python.org/download/alternatives 5-Jan-15 71 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 72. Famous Apps. written in python • Dropbox: A web-based file hosting service • BitTorrent: original client, along with several derivatives. • Ubuntu Software Center: A graphical package manager, installed by default in Ubuntu 9.10 and higher. • More: • http://en.wikipedia.org/wiki/List_of_Python_software 5-Jan-15 72 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 73. Summary • Python is • High-Level • Multi-Paradigm • and has • Dynamic Type • Strong Type • and use • Call by Reference(and value) • Static (and Dynamic) Scope 5-Jan-15 73 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 74. Reference 1. Python Official Website • http://python.org/ 2. Python 3 Documentation • http://docs.python.org/3/ 3. Python Tutorials • http://www.tutorialspoint.com/python/ 4. Learning Python, Fifth Edition • Mark Lutz, Published by O’Reilly Media, Inc. 2013 5-Jan-15 74 of 75Intro. To Python [Morteza Zakeri – University of Arak]
  • 75. Thank you for your attention. Slides will available on: • http://micropedia.ir/python