SlideShare a Scribd company logo
Introduction
to Python
Presented
by
MOHAMMED
RAFI.R.M
3rd MCA
CONTENTS
Python in general
 What is python?
• High level programming language
• Emphasize on code readability
• Very clear syntax + large and comprehensive
standard library
• Multiprogramming paradigm: OO, imperative,
functional, procedural, reflective
• A fully dynamic type system and automatic
memory management
• Scripting language + standalone executable
program + interpreter
• Can run on many platform: Windows, Linux,
Mactonish
• Updates:
• Newest version: 3.2.2 (CPython,JPython,
IronPython)
Why Do People Use Python?
Because there are many programming languages
available today, this is the usual first question of
newcomers.
 Software quality
 Developer productivity
 Program portability
 Support libraries
 Component integration
 Enjoyment
 Python execution speed may not always be as fast
as that of compiled languages such as C and C++
 Whether you will ever care about the execution
speed difference depends on what kinds of
programs you write.
 Processing a file or constructing a graphical user
interface (GUI), your program will actually run at C
speed, since such tasks are immediately
dispatched to compiled C code inside the Python
interpreter.
Who Uses Python Today?
 Google makes extensive use of Python in its web
search systems, and employs Python’s creator.
 The YouTube video sharing service is largely written
in Python.
 The popular BitTorrent peer-to-peer file sharing
system is a Python program.
 Google’s popular App Engine web development
framework uses Python as its application language.
 EVE Online, a Massively Multiplayer Online Game
(MMOG), makes extensive use of Python.
 Maya, a powerful integrated 3D modeling
and animation system, provides a Python
scripting API.
 Intel, Cisco, Hewlett-Packard, Seagate,
Qualcomm, and IBM use Python for
hardware testing.
 Industrial Light & Magic, Pixar, and others
use Python in the production of animated
movies.
 JPMorgan Chase, UBS, Getco, and Citadel
apply Python for financial market
forecasting.
Python’s Capability:
 System Programming
 GUI
 Internet Scripting
 Component Integration
 Database Programming
 Rapid Prototyping
 Numeric and Scientific Programming
 Gaming, Images, Serial Ports, XML, Robots,
and More
Python’s Technical Strengths:
 It’s Object-Oriented
 It’s Free
 It’s Portable
 It’s Powerful
-Dynamic typing
-Automatic memory management
-Programming-in-the-large support
-Built-in object types
-Built-in tools
-Library utilities
-Third-party utilities
 It’s Mixable
 It’s Easy to Use
 It’s Easy to Learn
 History of Python
Python was conceived in the late1980s and its
implementation was started in December
1989 by Guido van Rossum at CWI in the
Netherlands as a successor to the ABC
programming language capable of exception
handling and interfacing with the Amoeba
operating system. Van Rossum is Python's principal
author, and his continuing central role in deciding
the direction of Python is reflected in the title given
to him by the Python community, Benevolent
Dictator for Life (BDFL).
How Python Runs Programs ?
 Windows users fetch and run a self-installing
executable file that puts Python on their
machines. Simply double-click and say Yes
or Next at all prompts.
 Linux and Mac OS X users probably already
have a usable Python preinstalled on their
computers—it’s a standard component on
these platforms today.
 Some Linux and Mac OS X users (and most
Unix users) compile Python from its full
source code distribution package.
 The Python Virtual Machine (PVM)
- Once your program has been compiled to
byte code (or the byte code has been loaded
from existing .pyc files), it is shipped off for
execution to something generally known as the
Python Virtual Machine
- The PVM is the runtime engine of Python
- It’s always present as part of the Python
system, and it’s the component that truly runs
your scripts. Technically, it’s just the last step of
what is called the “Python interpreter.”
 Python Implementation Alternatives
 CPython
 Jython
 Ironpython
How to run Python?
 The Interactive Prompt
 simplest way to run Python programs is to
type them at Python’s interactive
command line sometimes called the
interactive prompt. There are a variety of
ways to start this command line: in an IDE,
from a system console, and so on.
 The most platformneutral way to start an
interactive interpreter session is usually just
to type python at your operating system’s
prompt, without any arguments.
• On Windows, you can type python in a DOS
console window
• On Unix, Linux, and Mac OS X, you might type this
command in a shell or terminal window .
• Other systems may use similar or platform-specific
devices. On handheld devices,for example, you
generally click the Python icon in the home or
application window to launch an interactive
session
 If you have not set your shell’s PATH
environment variable to include Python’s
install directory, you may need to
replace the word “python” with the full
path to the Python executable on your
machine. On Unix, Linux, and similar,
/usr/local/bin/python
 or /usr/bin/python will often suffice. On
Windows, try typing C:Python30python
(for version 3.0)
Lists
Dictionaries
Tuples
Files
Numeric Typing
Dynamic Typing
 Ordered collections of arbitrary objects
 Accessed by offset
 Variable-length, heterogeneous, and
arbitrarily nestable
 Of the category “mutable sequence”
 Arrays of object references
 Accessed by key, not offset
 Variable-length, heterogeneous, and
arbitrarily nestable
 Of the category “mutable mapping”
 Tables of object references (hash
tables)
 Ordered collections of arbitrary objects
 Accessed by offset
 Of the category “immutable sequence”
 Fixed-length, heterogeneous, and
arbitrarily nestable
 Arrays of object references
 Integers and floating-point numbers
 Complex numbers
 Fixed-precision decimal numbers
 Rational fraction numbers
 Sets
 Booleans
 Unlimited integer precision
 A variety of numeric built-ins and
modules
 Variables, Objects, References:
•Variables are entries in a system
table, with spaces for links to objects.
•Objects are pieces of allocated
memory, with enough space to
represent the values for which they
stand.
•References are automatically
followed pointers from variables to
objects.
• Notices:
It’s also just the default: if you don’t want such
behavior, you can request that Python copy objects
instead of making references.
 Notices (next):
• “is” function returns False if the names point to
equivalent but different
objects, as is the case when we run two different literal
expressions.
• Small integers and strings are cached and reused,
though, is tells us they reference the same single object.
Statements
Assignment, Expression,
Print
Conditional statements
Loop statements
Iterations and
comprehensions
Python program structures:
• Programs are composed of modules.
• Modules contain statements.
• Statements contain expressions.
• Expressions create and process
objects.
 Assignment Properties:
• Assignments create object references
• Names are created when first assigned
• Names must be assigned before being
referenced
• Some operations perform assignments
implicitly
Assignment Statement Forms:
 Syntax: (underscore or letter) + (any number of
letters, digits, or underscores)
 Case matters: SPAM is not the same as spam
 Reserved words are off-limits
 Call format
 Example:
 General Format:
The if/else ternary expression:
Example:
Conditional expression:
 Any nonzero number or nonempty object is true.
 Zero numbers, empty objects, and the special
object
None are considered false.
 Comparisons and equality tests are applied
recursively to data structures.
 Comparisons and equality tests return True or False
(custom versions of 1 and 0).
 Boolean “and” and “or” operators return a true or
false operand object
• “and” and “or” operands:
 General while format:
 Notice:
 General Format:
 Loop Coding Techniques:
• The built-in range function produces a
series of successively higher integers, which
can be used as indexes in a for.
• The built-in zip function returns a series of
parallel-item tuples,which can be used to
traverse multiple sequences in a for.
• Notice: for loops typically run quicker
than while-based counter loops, it’s to your
advantage to use tools like these that allow
you to use for when possible.
 Iterable:
• an object is considered iterable if it is either a
physically stored sequence or an object that
produces one result at a time in the context of an
iteration tool like a for loop.
• iterable objects include both physical sequences
and virtual sequences computed on demand.
 Iterations:
• Any object with a __next__ method to advance
to a next result,which raises Stop Iteration at the
end of the series of results, is considered iterable in
Python.
• Example:
 • Example:
• (x + 10): arbitrary expression
• (for x in L): iterable object
• Extend List Comprehension:
 Iterators associated:
• built-in type :set, list, dictionary, tuple, file
• Dictionary method: keys, values, items
• Built-in function: range(multipleiterator), map, zip,
filter (single)
 • Examples:
Function Basics
Scope
Arguments
Function Advanced
Iterations and
ComprehensionAdvanced
 Function: A function is a device that groups
a set of statements so they can be run
more than once in a program.
 Why use?:
• Maximizing code reuse and minimizing
redundancy
• Procedural decomposition
 General format:
 Use “def” statements:
 Three different scopes
• If a variable is assigned inside a def, it is local to
that function.
• If a variable is assigned in an enclosing def, it is
nonlocal to nested functions.
• If a variable is assigned outside all defs, it is global
to the entire file.
 Notice:
 • All names assigned inside a function def
statement (or a lambda,an expression we’ll meet
later) are locals by default.
 • Functions can freely use names as-signed in
syntactically enclosing functions and the global
scope, but they must declare such nonlocals and
globals in order to change them.
• Global Statement:
• Other ways to access Globals
 Factory function
• These terms refer to a function object that
remembers values in enclosing
scopes regardless of whether those scopes are still
present in memory.
• Nested scope and lambda:
 The nonlocal statement:
• Is a close cousin to global
• Like global: nonlocal declares that a name will
be changed in an enclosing scope.
 Unlike global:
• nonlocal applies to a name in an enclosing
function’s scope, not the global module scope
outside all defs.
• nonlocal names must already exist in the
enclosing function’s scope when declared
Format:
• Arguments are passed by automatically assigning
objects to local variable names.
• Assigning to argument names inside a function does
not affect the caller.
• Changing a mutable object argument in a function
may impact the caller.
• Immutable arguments are effectively passed “by
value.”
• Mutable arguments are effectively passed “by
pointer.”
 General guidelines:
• Coupling: use arguments for inputs and return
for outputs.
• Coupling: use global variables only when truly
necessary.
• Coupling: don’t change mutable arguments
unless the caller expects it.
• Cohesion: each function should have a single,
unified purpose.
• Size: each function should be relatively small.
• Coupling: avoid changing variables in another
module file directly
 Examples
• Alternatives
 Lambda format:
• Use lambda for:
-inline a function definition
-defer execution of a piece of code
• lambda is an expression, not a statement
• lambda’s body is a single expression, not a block
of statements.
• If you have larger logic to code, use def; lambda is
for small pieces of inline code. On the other hand,
you may find these techniques useful in moderation
• Examples:
 List Comprehension:
• Vs. Map:
 • Vs. filter:
 Generators:
• Generator functions: are coded as normal def
statements but use yield statements to return results
one at a time, suspending and resuming their state
between each.
• Generator expressions: are similar to the list
comprehensions of the prior section, but they
return an object that produces results on demand
instead of building a result list.
 Generator functions
Class Coding Basics
Class Coding Detail
Advanced Class topics
 OOP program must show:
• Abstraction (or sometimes called encapsulation)
• Inheritance (vs. composition)
• Polymorphism
• Class vs. Instance Object:
 Class: Serve as instance factories. Their attributes
provide behavior—data and functions—that is
inherited by all the instances generated from them.
 Instance: Represent the concrete items in a
program’s domain.Their attributes record data that
varies per specific object
 Each class statement generates a new
class object.
 Each time a class is called, it generates a
new instance object.
 Instances are automatically linked to the
classes from which they are created.
 Classes are linked to their superclasses by
listing them in parentheses in a class header
line; the left-to-right order there gives the
order in the tree.
 Notice:
• Python uses multiple inheritance: if there is
more than one superclass listed in
parentheses in a class statement (like C1’s
here), their left-to-right order gives the order
in which those superclasses will be
searched for attributes.
• Attributes are usually attached to classes by
assignments made within class statements,
and not nested inside function def
statements.
• Attributes are usually attached to instances
by assignments to a special argument
passed to functions inside classes, called
self.
 Class Object:
• The class statement creates a class object and
assigns it a name.
• Assignments inside class statements make class
attributes.
• Class attributes provide object state and behavior.
 Instance Object:
• Calling a class object like a function makes a new
instance object.
• Each instance object inherits class attributes and
gets its own namespace.
• Assignments to attributes of self in methods make
per-instance attributes.
 Class statement:
• Assigning names inside the class statement makes
class attributes, and nested defs make class
methods, but other assignments make attributes,
too.
 Examples:
 Method call:
 I believe the trial has shown conclusively that it is both
possible and desirable to use Python as the principal
teaching language:
 it is Free (as in both cost and source code).
 it is a flexible tool that allows both the teaching of
traditional procedural programming and modern OOP;
It can be used to teach a large number of transferable
skills;
 it is a real-world programming language that can
be and is used in academia and the commercial world;
 it appears to be quicker to learn and, in combination
with its many libraries, this offers the possibility of more
rapid student development allowing the course to be
made more challenging and varied;
and most importantly, its clean syntax offers
increased understanding and enjoyment for
students;
 Python should be used as the first year teaching
language. If used it will be possible to teach
students more programming and less of the
peculiarities of a particular language. Teaching a
mid-level language like C in just one day is
inadvisable. Too much time must be spent
teaching C and not enough time teaching generic
skills to students with no programming experience.
 In conclusion, Python offers the optimum
compromise of teach ability and applicability.
 Www.learnpython.org/
 www.pythontutor.com/‎
 Pythonbooks.revolunet.com/‎
 https://developers.google.com/edu/pyt
hon/‎
 Learning Python (3th Edition) - Ascher,
Lutz (O'Reilly, 2008)
Introduction to python
Introduction to python

More Related Content

What's hot

Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)
Paige Bailey
 
What is Python? | Edureka
What is Python? | EdurekaWhat is Python? | Edureka
What is Python? | Edureka
Edureka!
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
Nowell Strite
 
Introduction To Python | Edureka
Introduction To Python | EdurekaIntroduction To Python | Edureka
Introduction To Python | Edureka
Edureka!
 
python presntation 2.pptx
python presntation 2.pptxpython presntation 2.pptx
python presntation 2.pptx
Arpittripathi45
 
Introduction to Basics of Python
Introduction to Basics of PythonIntroduction to Basics of Python
Introduction to Basics of Python
Elewayte
 
Beginning Python Programming
Beginning Python ProgrammingBeginning Python Programming
Beginning Python Programming
St. Petersburg College
 
Python Course | Python Programming | Python Tutorial | Python Training | Edureka
Python Course | Python Programming | Python Tutorial | Python Training | EdurekaPython Course | Python Programming | Python Tutorial | Python Training | Edureka
Python Course | Python Programming | Python Tutorial | Python Training | Edureka
Edureka!
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
Srinivas Narasegouda
 
Intro to Python Programming Language
Intro to Python Programming LanguageIntro to Python Programming Language
Intro to Python Programming Language
Dipankar Achinta
 
Basics of python
Basics of pythonBasics of python
Basics of python
Jatin Kochhar
 
Python basics
Python basicsPython basics
Python basics
Hoang Nguyen
 
Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02
Fariz Darari
 
Python 3 Programming Language
Python 3 Programming LanguagePython 3 Programming Language
Python 3 Programming Language
Tahani Al-Manie
 
Let’s Learn Python An introduction to Python
Let’s Learn Python An introduction to Python Let’s Learn Python An introduction to Python
Let’s Learn Python An introduction to Python
Jaganadh Gopinadhan
 
Loops in Python
Loops in PythonLoops in Python
Loops in Python
Arockia Abins
 
Python
PythonPython
Introduction to python 3
Introduction to python 3Introduction to python 3
Introduction to python 3
Youhei Sakurai
 

What's hot (20)

Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)
 
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
 
Introduction To Python | Edureka
Introduction To Python | EdurekaIntroduction To Python | Edureka
Introduction To Python | Edureka
 
python presntation 2.pptx
python presntation 2.pptxpython presntation 2.pptx
python presntation 2.pptx
 
Introduction to Basics of Python
Introduction to Basics of PythonIntroduction to Basics of Python
Introduction to Basics of Python
 
Beginning Python Programming
Beginning Python ProgrammingBeginning Python Programming
Beginning Python Programming
 
Python Course | Python Programming | Python Tutorial | Python Training | Edureka
Python Course | Python Programming | Python Tutorial | Python Training | EdurekaPython Course | Python Programming | Python Tutorial | Python Training | Edureka
Python Course | Python Programming | Python Tutorial | Python Training | Edureka
 
Python - the basics
Python - the basicsPython - the basics
Python - the basics
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
 
Intro to Python Programming Language
Intro to Python Programming LanguageIntro to Python Programming Language
Intro to Python Programming Language
 
Basics of python
Basics of pythonBasics of python
Basics of python
 
Python basics
Python basicsPython basics
Python basics
 
Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02
 
Python 3 Programming Language
Python 3 Programming LanguagePython 3 Programming Language
Python 3 Programming Language
 
Let’s Learn Python An introduction to Python
Let’s Learn Python An introduction to Python Let’s Learn Python An introduction to Python
Let’s Learn Python An introduction to Python
 
Loops in Python
Loops in PythonLoops in Python
Loops in Python
 
Pandas
PandasPandas
Pandas
 
Python
PythonPython
Python
 
Introduction to python 3
Introduction to python 3Introduction to python 3
Introduction to python 3
 

Viewers also liked

Guide 2013 ademe des aides financieres pour la construction et la rénovation
Guide 2013 ademe des aides financieres pour la construction et la rénovationGuide 2013 ademe des aides financieres pour la construction et la rénovation
Guide 2013 ademe des aides financieres pour la construction et la rénovation
Build Green
 
Introduction to Hadoop and Hadoop component
Introduction to Hadoop and Hadoop component Introduction to Hadoop and Hadoop component
Introduction to Hadoop and Hadoop component
rebeccatho
 
Business intelligence
Business intelligenceBusiness intelligence
Business intelligencecrazytechnet
 
Big data Analytics Hadoop
Big data Analytics HadoopBig data Analytics Hadoop
Big data Analytics Hadoop
Mishika Bharadwaj
 
Spark dataframe
Spark dataframeSpark dataframe
Spark dataframe
Modern Data Stack France
 
Introduction To Big Data Analytics On Hadoop - SpringPeople
Introduction To Big Data Analytics On Hadoop - SpringPeopleIntroduction To Big Data Analytics On Hadoop - SpringPeople
Introduction To Big Data Analytics On Hadoop - SpringPeople
SpringPeople
 
Fuzzy c means manual work
Fuzzy c means manual workFuzzy c means manual work
Fuzzy c means manual work
Dr.E.N.Sathishkumar
 
Social media with big data analytics
Social media with big data analyticsSocial media with big data analytics
Social media with big data analytics
Universiti Technologi Malaysia (UTM)
 
Big Data Analytics : A Social Network Approach
Big Data Analytics : A Social Network ApproachBig Data Analytics : A Social Network Approach
Big Data Analytics : A Social Network Approach
Andry Alamsyah
 
Cloud History 101
Cloud History 101Cloud History 101
Cloud History 101
Mark Heinrich
 
Big Data Revolution: Are You Ready for the Data Overload?
Big Data Revolution: Are You Ready for the Data Overload?Big Data Revolution: Are You Ready for the Data Overload?
Big Data Revolution: Are You Ready for the Data Overload?
Aleah Radovich
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
Syed Zaid Irshad
 
Big Data
Big DataBig Data
Big Data
NGDATA
 
The Future of Real-Time in Spark
The Future of Real-Time in SparkThe Future of Real-Time in Spark
The Future of Real-Time in Spark
Reynold Xin
 
MapReduce - Hadoop - Big Data
MapReduce - Hadoop - Big DataMapReduce - Hadoop - Big Data
MapReduce - Hadoop - Big Data
Nafiz Ishtiaque Ahmed
 
What is Big Data?
What is Big Data?What is Big Data?
What is Big Data?
Bernard Marr
 
IT in Healthcare
IT in HealthcareIT in Healthcare
IT in Healthcare
NetApp
 

Viewers also liked (19)

Guide 2013 ademe des aides financieres pour la construction et la rénovation
Guide 2013 ademe des aides financieres pour la construction et la rénovationGuide 2013 ademe des aides financieres pour la construction et la rénovation
Guide 2013 ademe des aides financieres pour la construction et la rénovation
 
Introduction to Hadoop and Hadoop component
Introduction to Hadoop and Hadoop component Introduction to Hadoop and Hadoop component
Introduction to Hadoop and Hadoop component
 
Business intelligence
Business intelligenceBusiness intelligence
Business intelligence
 
Big data Analytics Hadoop
Big data Analytics HadoopBig data Analytics Hadoop
Big data Analytics Hadoop
 
Spark dataframe
Spark dataframeSpark dataframe
Spark dataframe
 
Introduction To Big Data Analytics On Hadoop - SpringPeople
Introduction To Big Data Analytics On Hadoop - SpringPeopleIntroduction To Big Data Analytics On Hadoop - SpringPeople
Introduction To Big Data Analytics On Hadoop - SpringPeople
 
Fuzzy c means manual work
Fuzzy c means manual workFuzzy c means manual work
Fuzzy c means manual work
 
Social media with big data analytics
Social media with big data analyticsSocial media with big data analytics
Social media with big data analytics
 
Big Data Analytics : A Social Network Approach
Big Data Analytics : A Social Network ApproachBig Data Analytics : A Social Network Approach
Big Data Analytics : A Social Network Approach
 
Cloud History 101
Cloud History 101Cloud History 101
Cloud History 101
 
Big Data Revolution: Are You Ready for the Data Overload?
Big Data Revolution: Are You Ready for the Data Overload?Big Data Revolution: Are You Ready for the Data Overload?
Big Data Revolution: Are You Ready for the Data Overload?
 
Big data ppt
Big data pptBig data ppt
Big data ppt
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Big Data
Big DataBig Data
Big Data
 
The Future of Real-Time in Spark
The Future of Real-Time in SparkThe Future of Real-Time in Spark
The Future of Real-Time in Spark
 
MapReduce - Hadoop - Big Data
MapReduce - Hadoop - Big DataMapReduce - Hadoop - Big Data
MapReduce - Hadoop - Big Data
 
What is Big Data?
What is Big Data?What is Big Data?
What is Big Data?
 
Big data ppt
Big  data pptBig  data ppt
Big data ppt
 
IT in Healthcare
IT in HealthcareIT in Healthcare
IT in Healthcare
 

Similar to Introduction to python

MODULE 1.pptx
MODULE 1.pptxMODULE 1.pptx
MODULE 1.pptx
KPDDRAVIDIAN
 
Python programming language introduction unit
Python programming language introduction unitPython programming language introduction unit
Python programming language introduction unit
michaelaaron25322
 
Programming with Python: Week 1
Programming with Python: Week 1Programming with Python: Week 1
Programming with Python: Week 1
Ahmet Bulut
 
Python Course In Chandigarh
Python Course In ChandigarhPython Course In Chandigarh
Python Course In Chandigarh
Excellence Academy
 
What is python
What is pythonWhat is python
What is python
faizrashid1995
 
Session-1_Introduction to Python.pptx
Session-1_Introduction to Python.pptxSession-1_Introduction to Python.pptx
Session-1_Introduction to Python.pptx
WajidAliHashmi2
 
Python_Introduction_Good_PPT.pptx
Python_Introduction_Good_PPT.pptxPython_Introduction_Good_PPT.pptx
Python_Introduction_Good_PPT.pptx
lemonchoos
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python Programming
Akhil Kaushik
 
REPORT ON AUDIT COURSE PYTHON BY SANA 2.pdf
REPORT ON AUDIT COURSE PYTHON BY SANA 2.pdfREPORT ON AUDIT COURSE PYTHON BY SANA 2.pdf
REPORT ON AUDIT COURSE PYTHON BY SANA 2.pdf
Sana Khan
 
Python quick guide1
Python quick guide1Python quick guide1
Python quick guide1Kanchilug
 
introduction of python in data science
introduction of python in data scienceintroduction of python in data science
introduction of python in data science
bhavesh lande
 
Python (3).pdf
Python (3).pdfPython (3).pdf
Python (3).pdf
samiwaris2
 
Python PPT 50.pptx
Python PPT 50.pptxPython PPT 50.pptx
Python PPT 50.pptx
mohamedDarwishICTHOD
 
Python tutorial for beginners - Tib academy
Python tutorial for beginners - Tib academyPython tutorial for beginners - Tib academy
Python tutorial for beginners - Tib academy
TIB Academy
 
intro to python.pptx
intro to python.pptxintro to python.pptx
intro to python.pptx
UpasnaSharma37
 
01 python introduction
01 python introduction 01 python introduction
01 python introduction
Tamer Ahmed Farrag, PhD
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
Ranjith kumar
 
Python Course.docx
Python Course.docxPython Course.docx
Python Course.docx
AdnanAhmad57885
 
Python Programming Part 1.pdf
Python Programming Part 1.pdfPython Programming Part 1.pdf
Python Programming Part 1.pdf
percivalfernandez2
 
Python Programming Part 1.pdf
Python Programming Part 1.pdfPython Programming Part 1.pdf
Python Programming Part 1.pdf
percivalfernandez2
 

Similar to Introduction to python (20)

MODULE 1.pptx
MODULE 1.pptxMODULE 1.pptx
MODULE 1.pptx
 
Python programming language introduction unit
Python programming language introduction unitPython programming language introduction unit
Python programming language introduction unit
 
Programming with Python: Week 1
Programming with Python: Week 1Programming with Python: Week 1
Programming with Python: Week 1
 
Python Course In Chandigarh
Python Course In ChandigarhPython Course In Chandigarh
Python Course In Chandigarh
 
What is python
What is pythonWhat is python
What is python
 
Session-1_Introduction to Python.pptx
Session-1_Introduction to Python.pptxSession-1_Introduction to Python.pptx
Session-1_Introduction to Python.pptx
 
Python_Introduction_Good_PPT.pptx
Python_Introduction_Good_PPT.pptxPython_Introduction_Good_PPT.pptx
Python_Introduction_Good_PPT.pptx
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python Programming
 
REPORT ON AUDIT COURSE PYTHON BY SANA 2.pdf
REPORT ON AUDIT COURSE PYTHON BY SANA 2.pdfREPORT ON AUDIT COURSE PYTHON BY SANA 2.pdf
REPORT ON AUDIT COURSE PYTHON BY SANA 2.pdf
 
Python quick guide1
Python quick guide1Python quick guide1
Python quick guide1
 
introduction of python in data science
introduction of python in data scienceintroduction of python in data science
introduction of python in data science
 
Python (3).pdf
Python (3).pdfPython (3).pdf
Python (3).pdf
 
Python PPT 50.pptx
Python PPT 50.pptxPython PPT 50.pptx
Python PPT 50.pptx
 
Python tutorial for beginners - Tib academy
Python tutorial for beginners - Tib academyPython tutorial for beginners - Tib academy
Python tutorial for beginners - Tib academy
 
intro to python.pptx
intro to python.pptxintro to python.pptx
intro to python.pptx
 
01 python introduction
01 python introduction 01 python introduction
01 python introduction
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Python Course.docx
Python Course.docxPython Course.docx
Python Course.docx
 
Python Programming Part 1.pdf
Python Programming Part 1.pdfPython Programming Part 1.pdf
Python Programming Part 1.pdf
 
Python Programming Part 1.pdf
Python Programming Part 1.pdfPython Programming Part 1.pdf
Python Programming Part 1.pdf
 

Recently uploaded

How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
Nguyen Thanh Tu Collection
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 

Recently uploaded (20)

How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 

Introduction to python

  • 3. Python in general  What is python? • High level programming language • Emphasize on code readability • Very clear syntax + large and comprehensive standard library • Multiprogramming paradigm: OO, imperative, functional, procedural, reflective • A fully dynamic type system and automatic memory management • Scripting language + standalone executable program + interpreter • Can run on many platform: Windows, Linux, Mactonish
  • 4. • Updates: • Newest version: 3.2.2 (CPython,JPython, IronPython)
  • 5. Why Do People Use Python? Because there are many programming languages available today, this is the usual first question of newcomers.  Software quality  Developer productivity  Program portability  Support libraries  Component integration  Enjoyment
  • 6.  Python execution speed may not always be as fast as that of compiled languages such as C and C++  Whether you will ever care about the execution speed difference depends on what kinds of programs you write.  Processing a file or constructing a graphical user interface (GUI), your program will actually run at C speed, since such tasks are immediately dispatched to compiled C code inside the Python interpreter.
  • 7.
  • 8. Who Uses Python Today?  Google makes extensive use of Python in its web search systems, and employs Python’s creator.  The YouTube video sharing service is largely written in Python.  The popular BitTorrent peer-to-peer file sharing system is a Python program.  Google’s popular App Engine web development framework uses Python as its application language.  EVE Online, a Massively Multiplayer Online Game (MMOG), makes extensive use of Python.
  • 9.  Maya, a powerful integrated 3D modeling and animation system, provides a Python scripting API.  Intel, Cisco, Hewlett-Packard, Seagate, Qualcomm, and IBM use Python for hardware testing.  Industrial Light & Magic, Pixar, and others use Python in the production of animated movies.  JPMorgan Chase, UBS, Getco, and Citadel apply Python for financial market forecasting.
  • 10. Python’s Capability:  System Programming  GUI  Internet Scripting  Component Integration  Database Programming  Rapid Prototyping  Numeric and Scientific Programming  Gaming, Images, Serial Ports, XML, Robots, and More
  • 11. Python’s Technical Strengths:  It’s Object-Oriented  It’s Free  It’s Portable  It’s Powerful -Dynamic typing -Automatic memory management -Programming-in-the-large support -Built-in object types
  • 12. -Built-in tools -Library utilities -Third-party utilities  It’s Mixable  It’s Easy to Use  It’s Easy to Learn
  • 13.  History of Python Python was conceived in the late1980s and its implementation was started in December 1989 by Guido van Rossum at CWI in the Netherlands as a successor to the ABC programming language capable of exception handling and interfacing with the Amoeba operating system. Van Rossum is Python's principal author, and his continuing central role in deciding the direction of Python is reflected in the title given to him by the Python community, Benevolent Dictator for Life (BDFL).
  • 14.
  • 15. How Python Runs Programs ?
  • 16.  Windows users fetch and run a self-installing executable file that puts Python on their machines. Simply double-click and say Yes or Next at all prompts.  Linux and Mac OS X users probably already have a usable Python preinstalled on their computers—it’s a standard component on these platforms today.  Some Linux and Mac OS X users (and most Unix users) compile Python from its full source code distribution package.
  • 17.  The Python Virtual Machine (PVM) - Once your program has been compiled to byte code (or the byte code has been loaded from existing .pyc files), it is shipped off for execution to something generally known as the Python Virtual Machine - The PVM is the runtime engine of Python - It’s always present as part of the Python system, and it’s the component that truly runs your scripts. Technically, it’s just the last step of what is called the “Python interpreter.”
  • 18.  Python Implementation Alternatives  CPython  Jython  Ironpython
  • 19. How to run Python?  The Interactive Prompt  simplest way to run Python programs is to type them at Python’s interactive command line sometimes called the interactive prompt. There are a variety of ways to start this command line: in an IDE, from a system console, and so on.  The most platformneutral way to start an interactive interpreter session is usually just to type python at your operating system’s prompt, without any arguments.
  • 20.
  • 21. • On Windows, you can type python in a DOS console window • On Unix, Linux, and Mac OS X, you might type this command in a shell or terminal window . • Other systems may use similar or platform-specific devices. On handheld devices,for example, you generally click the Python icon in the home or application window to launch an interactive session
  • 22.  If you have not set your shell’s PATH environment variable to include Python’s install directory, you may need to replace the word “python” with the full path to the Python executable on your machine. On Unix, Linux, and similar, /usr/local/bin/python  or /usr/bin/python will often suffice. On Windows, try typing C:Python30python (for version 3.0)
  • 23.
  • 25.  Ordered collections of arbitrary objects  Accessed by offset  Variable-length, heterogeneous, and arbitrarily nestable  Of the category “mutable sequence”  Arrays of object references
  • 26.
  • 27.
  • 28.  Accessed by key, not offset  Variable-length, heterogeneous, and arbitrarily nestable  Of the category “mutable mapping”  Tables of object references (hash tables)
  • 29.
  • 30.
  • 31.  Ordered collections of arbitrary objects  Accessed by offset  Of the category “immutable sequence”  Fixed-length, heterogeneous, and arbitrarily nestable  Arrays of object references
  • 32.
  • 33.
  • 34.
  • 35.  Integers and floating-point numbers  Complex numbers  Fixed-precision decimal numbers  Rational fraction numbers  Sets  Booleans  Unlimited integer precision  A variety of numeric built-ins and modules
  • 36.
  • 37.
  • 38.  Variables, Objects, References: •Variables are entries in a system table, with spaces for links to objects. •Objects are pieces of allocated memory, with enough space to represent the values for which they stand. •References are automatically followed pointers from variables to objects.
  • 39.
  • 40.
  • 41.
  • 42. • Notices: It’s also just the default: if you don’t want such behavior, you can request that Python copy objects instead of making references.
  • 43.  Notices (next): • “is” function returns False if the names point to equivalent but different objects, as is the case when we run two different literal expressions. • Small integers and strings are cached and reused, though, is tells us they reference the same single object.
  • 44.
  • 45.
  • 47. Python program structures: • Programs are composed of modules. • Modules contain statements. • Statements contain expressions. • Expressions create and process objects.
  • 48.
  • 49.
  • 50.
  • 51.  Assignment Properties: • Assignments create object references • Names are created when first assigned • Names must be assigned before being referenced • Some operations perform assignments implicitly Assignment Statement Forms:
  • 52.
  • 53.  Syntax: (underscore or letter) + (any number of letters, digits, or underscores)  Case matters: SPAM is not the same as spam  Reserved words are off-limits
  • 54.
  • 57.  General Format: The if/else ternary expression:
  • 59. Conditional expression:  Any nonzero number or nonempty object is true.  Zero numbers, empty objects, and the special object None are considered false.  Comparisons and equality tests are applied recursively to data structures.  Comparisons and equality tests return True or False (custom versions of 1 and 0).  Boolean “and” and “or” operators return a true or false operand object
  • 60. • “and” and “or” operands:
  • 61.  General while format:
  • 64.  Loop Coding Techniques: • The built-in range function produces a series of successively higher integers, which can be used as indexes in a for. • The built-in zip function returns a series of parallel-item tuples,which can be used to traverse multiple sequences in a for. • Notice: for loops typically run quicker than while-based counter loops, it’s to your advantage to use tools like these that allow you to use for when possible.
  • 65.
  • 66.
  • 67.  Iterable: • an object is considered iterable if it is either a physically stored sequence or an object that produces one result at a time in the context of an iteration tool like a for loop. • iterable objects include both physical sequences and virtual sequences computed on demand.  Iterations: • Any object with a __next__ method to advance to a next result,which raises Stop Iteration at the end of the series of results, is considered iterable in Python.
  • 69.  • Example: • (x + 10): arbitrary expression • (for x in L): iterable object • Extend List Comprehension:
  • 70.  Iterators associated: • built-in type :set, list, dictionary, tuple, file • Dictionary method: keys, values, items • Built-in function: range(multipleiterator), map, zip, filter (single)  • Examples:
  • 71.
  • 72.
  • 74.  Function: A function is a device that groups a set of statements so they can be run more than once in a program.  Why use?: • Maximizing code reuse and minimizing redundancy • Procedural decomposition
  • 75.
  • 77.  Use “def” statements:
  • 78.
  • 79.  Three different scopes • If a variable is assigned inside a def, it is local to that function. • If a variable is assigned in an enclosing def, it is nonlocal to nested functions. • If a variable is assigned outside all defs, it is global to the entire file.  Notice:  • All names assigned inside a function def statement (or a lambda,an expression we’ll meet later) are locals by default.  • Functions can freely use names as-signed in syntactically enclosing functions and the global scope, but they must declare such nonlocals and globals in order to change them.
  • 81. • Other ways to access Globals
  • 82.
  • 83.
  • 84.  Factory function • These terms refer to a function object that remembers values in enclosing scopes regardless of whether those scopes are still present in memory.
  • 85. • Nested scope and lambda:
  • 86.  The nonlocal statement: • Is a close cousin to global • Like global: nonlocal declares that a name will be changed in an enclosing scope.  Unlike global: • nonlocal applies to a name in an enclosing function’s scope, not the global module scope outside all defs. • nonlocal names must already exist in the enclosing function’s scope when declared Format:
  • 87.
  • 88.
  • 89. • Arguments are passed by automatically assigning objects to local variable names. • Assigning to argument names inside a function does not affect the caller. • Changing a mutable object argument in a function may impact the caller. • Immutable arguments are effectively passed “by value.” • Mutable arguments are effectively passed “by pointer.”
  • 90.
  • 91.
  • 92.
  • 93.  General guidelines: • Coupling: use arguments for inputs and return for outputs. • Coupling: use global variables only when truly necessary. • Coupling: don’t change mutable arguments unless the caller expects it. • Cohesion: each function should have a single, unified purpose. • Size: each function should be relatively small. • Coupling: avoid changing variables in another module file directly
  • 96.  Lambda format: • Use lambda for: -inline a function definition -defer execution of a piece of code • lambda is an expression, not a statement • lambda’s body is a single expression, not a block of statements. • If you have larger logic to code, use def; lambda is for small pieces of inline code. On the other hand, you may find these techniques useful in moderation
  • 99.  • Vs. filter:
  • 100.  Generators: • Generator functions: are coded as normal def statements but use yield statements to return results one at a time, suspending and resuming their state between each. • Generator expressions: are similar to the list comprehensions of the prior section, but they return an object that produces results on demand instead of building a result list.
  • 102.
  • 103.
  • 104. Class Coding Basics Class Coding Detail Advanced Class topics
  • 105.  OOP program must show: • Abstraction (or sometimes called encapsulation) • Inheritance (vs. composition) • Polymorphism • Class vs. Instance Object:  Class: Serve as instance factories. Their attributes provide behavior—data and functions—that is inherited by all the instances generated from them.  Instance: Represent the concrete items in a program’s domain.Their attributes record data that varies per specific object
  • 106.  Each class statement generates a new class object.  Each time a class is called, it generates a new instance object.  Instances are automatically linked to the classes from which they are created.  Classes are linked to their superclasses by listing them in parentheses in a class header line; the left-to-right order there gives the order in the tree.
  • 107.
  • 108.  Notice: • Python uses multiple inheritance: if there is more than one superclass listed in parentheses in a class statement (like C1’s here), their left-to-right order gives the order in which those superclasses will be searched for attributes.
  • 109. • Attributes are usually attached to classes by assignments made within class statements, and not nested inside function def statements. • Attributes are usually attached to instances by assignments to a special argument passed to functions inside classes, called self.
  • 110.  Class Object: • The class statement creates a class object and assigns it a name. • Assignments inside class statements make class attributes. • Class attributes provide object state and behavior.  Instance Object: • Calling a class object like a function makes a new instance object. • Each instance object inherits class attributes and gets its own namespace. • Assignments to attributes of self in methods make per-instance attributes.
  • 111.
  • 112.
  • 113.  Class statement: • Assigning names inside the class statement makes class attributes, and nested defs make class methods, but other assignments make attributes, too.
  • 116.  I believe the trial has shown conclusively that it is both possible and desirable to use Python as the principal teaching language:  it is Free (as in both cost and source code).  it is a flexible tool that allows both the teaching of traditional procedural programming and modern OOP; It can be used to teach a large number of transferable skills;  it is a real-world programming language that can be and is used in academia and the commercial world;  it appears to be quicker to learn and, in combination with its many libraries, this offers the possibility of more rapid student development allowing the course to be made more challenging and varied;
  • 117. and most importantly, its clean syntax offers increased understanding and enjoyment for students;  Python should be used as the first year teaching language. If used it will be possible to teach students more programming and less of the peculiarities of a particular language. Teaching a mid-level language like C in just one day is inadvisable. Too much time must be spent teaching C and not enough time teaching generic skills to students with no programming experience.  In conclusion, Python offers the optimum compromise of teach ability and applicability.
  • 118.  Www.learnpython.org/  www.pythontutor.com/‎  Pythonbooks.revolunet.com/‎  https://developers.google.com/edu/pyt hon/‎  Learning Python (3th Edition) - Ascher, Lutz (O'Reilly, 2008)