SlideShare a Scribd company logo
WHAT IS PYTHON?
by Gyuri Horak
WHY PYTHON?
WHY PYTHON!
Monty Python!
HISTORY
● 1989, Guido van Rossum, BDFL
● BDFL: benevolent dictator for life
○ successor of ABC
○ capable of exception handling
● 2000, Python 2
○ garbage collector
○ unicode support
○ community-backed development process
● 2008, Python 3 (not yet widely used)
WHAT IS PYTHON?
● open source
● object-oriented
● Everything is an object.
● structured
● You don't need to define any class if you don't want to.
● So both o-o and structured programming are supported, you can
even mix these techniques.
● a bit functional programming, AOP, metaprogramming
● Like list comprehensions: sqs = [x**2 for x in range(0, 10)]
● New classes can be created runtime, methods can be easily
replaced (monkey-patching)...
● dynamic typed, duck typing
● memory management (reference counting and cycle-detecting gc)
WHERE CAN I USE IT?
● CPython
○ reference implementation
○ wide range of C modules
○ Stackless, Unladen Swallow
● Jython
○ Python on JVM
● IronPython
○ Python on .NET
● PyPy
○ Python in Python
○ uses JIT, focuses on speed
WHO USES IT?
● Google (search, Youtube, GAE)
● Yahoo (maps, groups)
● Mozilla (addons website)
● Video games (Battlefield 2, Crystal Space 3D engine,
Civilization 4, ...)
● Movies (Industrial Light & Magic, Walt Disney, Blender,
...)
● Science (NASA, National Weather Service, ...)
● ...
THE ZEN OF PYTHON
The Zen of Python, by Tim Peters
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.
Readability counts.
...
HOW DOES IT LOOK LIKE?
● Indentation, no semicolon
● Style guide: PEP-8
● Docstrings: PEP-257, reST: PEP-287
def hello(name="World"):
"""Says hello to `name`
name -- the name to greet (default "World")
"""
if name is "Janos":
print "...hi!"
else:
print "Hello %s!" % name
# Python 3: print statement -> print() function
DATA TYPES
● None
● bool (True/False)
● int, long, float, complex [int, float, complex, Fraction]
● str, unicode [bytes, str] (!)
● list
● tuple
● dict
● set, frozenset
● ...
FLOW CONTROL STATEMENTS - IF
if a > b:
pass
elif b < a:
print "b<a"
else:
print "b=a"
pass is an empty statement, it does nothing.
No switch ... case, but you can have as much elif as you want. There's no a = b ? c : d operator neither, but
you can use if in the following way:
a = c if b else d
FLOW CONTROL STATEMENTS - WHILE
while a < b:
a += 1
FLOW CONTROL STATEMENTS - FOR
for x in l:
print x
It's not the conventional for, it's a foreach, l has to be an iterable.
Iterable objects are capable of returning its members one at a time, like
iterators or generators.
It's easy to simulate the conventional behavior with the range() function, but do
not do the following:
for i in range(0, 10):
print l[i]
BREAK, CONTINUE, ELSE
● break and continue work as usual
● you can define else block for for and while loops, they will be executed when
the loop terminates normally
for n in range(2, 100):
for x in range(2, n):
if n % x == 0:
print "%d == %d * %d" % (n, x, n/x)
break
else:
print "%d is a prime number" % n
EXCEPTION HANDLING
try:
result = x / y
except ZeroDivisionError as e:
print "y should not be 0!"
except:
traceback.print_exc()
else:
print "x / y =", result
finally:
print "we're in finally block"
FUNCTIONS
def fname(*args, **kwargs):
# function body
return returnvalue
No function/method overloading, but argument list can vary:
def example(a, b=12, c=False):
return b if c else a
>>> example(42)
42
>>> example(1, 20)
1
>>> example(1, 2, True)
2
>>> example(1, c=True)
12
CLASSES
class MyClass(object):
a = 42
def say_hello(self, name="World"):
print "Hello %s!" % name
return self.a
def __init__(self, a = None):
if a:
self.a = a
>>> i = MyClass(1)
>>> x = i.say_hello("Everyone")
Hello Everyone!
>>> x
1
● no private attributes/methods (_, __)
● methods are bound to instances:
● >>> sh = a.say_hello
>>> sh
<bound method MyClass.say_hello of <...(a)...>>
INHERITANCE
● Class A (old) <=> class A(object) (new)
● Don't use the old way, esp. not when considering multiple inheritance.
class MyClass(BC1, BC2, BC3):
def __init__(self):
if wrongway:
BC1.__init__(self)
BC2.__init__(self)
BC3.__init__(self)
else:
super(MyClass, self).__init__()
● method lookup order is well defined (BC1, BC1 bases, BC2, BC2 bases,
...)
MODULES, PACKAGES
● Module = file
● Package = directory containing __init__.py
Importing a module/package:
import os # the whole os package
import os.path # the os.path module
# the os.path.join function
import os.path.join as pathjoin
# everything imported into the current namespace
from sys import * # do not do this!
PYTHON 3
● some backward incompatible changes:
○ print statement -> print() function
○ b"..." for bytes, "..." for (unicode) strings
○ 1/2 = 0.5
○ classic classes removed
○ int/long -> int
○ ... lot of smaller changes/improvements
● standardization is not yet finalized
● libraries migrate quite slowly

More Related Content

What's hot (20)

PDF
Scroll pHAT HD に美咲フォント
Yuriko IKEDA
 
PDF
Algoritmos ensambladores
Maurock Charolastra Muñoz
 
PDF
Javascript status 2016
Arshavski Alexander
 
PDF
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...
Mail.ru Group
 
PDF
Taking Inspiration From The Functional World
Piotr Solnica
 
TXT
Xstartup
Ahmed Abdelazim
 
PDF
ELI5: What the heck is a Functor?
Punit Rathore
 
PDF
De 0 a 100 con Bash Shell Scripting y AWK
Adolfo Sanz De Diego
 
PDF
Introduction to Nim
Fred Heath
 
PDF
Regular Expressions: JavaScript And Beyond
Max Shirshin
 
PDF
The Lesser Known Features of ECMAScript 6
Bryan Hughes
 
PDF
JavaSE7 Launch Event: Java7xGroovy
Yasuharu Nakano
 
PDF
Rakudo
awwaiid
 
PDF
Why Kotlin is your next language?
Aliaksei Zhynhiarouski
 
PDF
Let's fly to the Kotlin Island. Just an introduction to Kotlin
Aliaksei Zhynhiarouski
 
PDF
Meet up symfony 16 juin 2017 - Les PSR
Julien Vinber
 
PDF
dplyr
Romain Francois
 
PDF
Orlando BarCamp Why Javascript Doesn't Suck
erockendude
 
PPTX
Javascript Common Mistakes
동수 장
 
PPT
FSE 2008
ericbodden
 
Scroll pHAT HD に美咲フォント
Yuriko IKEDA
 
Algoritmos ensambladores
Maurock Charolastra Muñoz
 
Javascript status 2016
Arshavski Alexander
 
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...
Mail.ru Group
 
Taking Inspiration From The Functional World
Piotr Solnica
 
Xstartup
Ahmed Abdelazim
 
ELI5: What the heck is a Functor?
Punit Rathore
 
De 0 a 100 con Bash Shell Scripting y AWK
Adolfo Sanz De Diego
 
Introduction to Nim
Fred Heath
 
Regular Expressions: JavaScript And Beyond
Max Shirshin
 
The Lesser Known Features of ECMAScript 6
Bryan Hughes
 
JavaSE7 Launch Event: Java7xGroovy
Yasuharu Nakano
 
Rakudo
awwaiid
 
Why Kotlin is your next language?
Aliaksei Zhynhiarouski
 
Let's fly to the Kotlin Island. Just an introduction to Kotlin
Aliaksei Zhynhiarouski
 
Meet up symfony 16 juin 2017 - Les PSR
Julien Vinber
 
Orlando BarCamp Why Javascript Doesn't Suck
erockendude
 
Javascript Common Mistakes
동수 장
 
FSE 2008
ericbodden
 

Similar to What is python (20)

PPT
FALLSEM2022-23_ITA3007_ETH_VL2022230100613_Reference_Material_I_23-09-2022_py...
admin369652
 
PPT
Introduction to Python For Diploma Students
SanjaySampat1
 
ODP
Programming Under Linux In Python
Marwan Osman
 
PDF
Tutorial on-python-programming
Chetan Giridhar
 
PPT
Python ppt
Mohita Pandey
 
PDF
web programming UNIT VIII python by Bhavsingh Maloth
Bhavsingh Maloth
 
PDF
Introduction To Programming with Python
Sushant Mane
 
ODP
An Intro to Python in 30 minutes
Sumit Raj
 
PPT
Python Kick Start
Karthik Prakash
 
PDF
Python Foundation – A programmer's introduction to Python concepts & style
Kevlin Henney
 
PPT
Pythonintroduction
-jyothish kumar sirigidi
 
PDF
Becoming a Pythonist
Raji Engg
 
PPT
Python basics to advanced in on ppt is available
nexasbravo2000sep
 
PDF
Lecture1_cis4930.pdf
zertash1
 
PPTX
Introduction to python
MaheshPandit16
 
PPTX
Introduction to python.pptx
pcjoshi02
 
PDF
Python An Intro
Arulalan T
 
PPT
Python for Engineers and Architects Stud
RaviRamachandraR
 
PPTX
Python for dummies
Roberto Stefanetti
 
PPTX
Python PPT by Sushil Sir.pptx
sushil155005
 
FALLSEM2022-23_ITA3007_ETH_VL2022230100613_Reference_Material_I_23-09-2022_py...
admin369652
 
Introduction to Python For Diploma Students
SanjaySampat1
 
Programming Under Linux In Python
Marwan Osman
 
Tutorial on-python-programming
Chetan Giridhar
 
Python ppt
Mohita Pandey
 
web programming UNIT VIII python by Bhavsingh Maloth
Bhavsingh Maloth
 
Introduction To Programming with Python
Sushant Mane
 
An Intro to Python in 30 minutes
Sumit Raj
 
Python Kick Start
Karthik Prakash
 
Python Foundation – A programmer's introduction to Python concepts & style
Kevlin Henney
 
Pythonintroduction
-jyothish kumar sirigidi
 
Becoming a Pythonist
Raji Engg
 
Python basics to advanced in on ppt is available
nexasbravo2000sep
 
Lecture1_cis4930.pdf
zertash1
 
Introduction to python
MaheshPandit16
 
Introduction to python.pptx
pcjoshi02
 
Python An Intro
Arulalan T
 
Python for Engineers and Architects Stud
RaviRamachandraR
 
Python for dummies
Roberto Stefanetti
 
Python PPT by Sushil Sir.pptx
sushil155005
 
Ad

More from EU Edge (16)

PDF
Synchronization with CouchDB and PouchDB
EU Edge
 
PDF
How I learned to Stop Worrying and Love the inline-block
EU Edge
 
PDF
Node.js
EU Edge
 
PDF
Advanced python
EU Edge
 
PDF
WebGL
EU Edge
 
PDF
Python alapu mobil backend
EU Edge
 
PDF
Res tful services
EU Edge
 
PDF
Open gl
EU Edge
 
PDF
Google glass a developers perspective
EU Edge
 
PDF
Google glass ict day presentation
EU Edge
 
PDF
How does it work the keyboard
EU Edge
 
PDF
Node webkit-meetup
EU Edge
 
PDF
Frontend meetup 2014.06.25
EU Edge
 
PDF
Eu edge intro
EU Edge
 
PDF
Halado css eu edge
EU Edge
 
PDF
Miért jó oktatóanyagot készíteni?
EU Edge
 
Synchronization with CouchDB and PouchDB
EU Edge
 
How I learned to Stop Worrying and Love the inline-block
EU Edge
 
Node.js
EU Edge
 
Advanced python
EU Edge
 
WebGL
EU Edge
 
Python alapu mobil backend
EU Edge
 
Res tful services
EU Edge
 
Open gl
EU Edge
 
Google glass a developers perspective
EU Edge
 
Google glass ict day presentation
EU Edge
 
How does it work the keyboard
EU Edge
 
Node webkit-meetup
EU Edge
 
Frontend meetup 2014.06.25
EU Edge
 
Eu edge intro
EU Edge
 
Halado css eu edge
EU Edge
 
Miért jó oktatóanyagot készíteni?
EU Edge
 
Ad

Recently uploaded (20)

PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PDF
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
PDF
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PPTX
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
PPTX
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PPTX
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
PDF
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 

What is python

  • 1. WHAT IS PYTHON? by Gyuri Horak
  • 4. HISTORY ● 1989, Guido van Rossum, BDFL ● BDFL: benevolent dictator for life ○ successor of ABC ○ capable of exception handling ● 2000, Python 2 ○ garbage collector ○ unicode support ○ community-backed development process ● 2008, Python 3 (not yet widely used)
  • 5. WHAT IS PYTHON? ● open source ● object-oriented ● Everything is an object. ● structured ● You don't need to define any class if you don't want to. ● So both o-o and structured programming are supported, you can even mix these techniques. ● a bit functional programming, AOP, metaprogramming ● Like list comprehensions: sqs = [x**2 for x in range(0, 10)] ● New classes can be created runtime, methods can be easily replaced (monkey-patching)... ● dynamic typed, duck typing ● memory management (reference counting and cycle-detecting gc)
  • 6. WHERE CAN I USE IT? ● CPython ○ reference implementation ○ wide range of C modules ○ Stackless, Unladen Swallow ● Jython ○ Python on JVM ● IronPython ○ Python on .NET ● PyPy ○ Python in Python ○ uses JIT, focuses on speed
  • 7. WHO USES IT? ● Google (search, Youtube, GAE) ● Yahoo (maps, groups) ● Mozilla (addons website) ● Video games (Battlefield 2, Crystal Space 3D engine, Civilization 4, ...) ● Movies (Industrial Light & Magic, Walt Disney, Blender, ...) ● Science (NASA, National Weather Service, ...) ● ...
  • 8. THE ZEN OF PYTHON The Zen of Python, by Tim Peters 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. Readability counts. ...
  • 9. HOW DOES IT LOOK LIKE? ● Indentation, no semicolon ● Style guide: PEP-8 ● Docstrings: PEP-257, reST: PEP-287 def hello(name="World"): """Says hello to `name` name -- the name to greet (default "World") """ if name is "Janos": print "...hi!" else: print "Hello %s!" % name # Python 3: print statement -> print() function
  • 10. DATA TYPES ● None ● bool (True/False) ● int, long, float, complex [int, float, complex, Fraction] ● str, unicode [bytes, str] (!) ● list ● tuple ● dict ● set, frozenset ● ...
  • 11. FLOW CONTROL STATEMENTS - IF if a > b: pass elif b < a: print "b<a" else: print "b=a" pass is an empty statement, it does nothing. No switch ... case, but you can have as much elif as you want. There's no a = b ? c : d operator neither, but you can use if in the following way: a = c if b else d
  • 12. FLOW CONTROL STATEMENTS - WHILE while a < b: a += 1
  • 13. FLOW CONTROL STATEMENTS - FOR for x in l: print x It's not the conventional for, it's a foreach, l has to be an iterable. Iterable objects are capable of returning its members one at a time, like iterators or generators. It's easy to simulate the conventional behavior with the range() function, but do not do the following: for i in range(0, 10): print l[i]
  • 14. BREAK, CONTINUE, ELSE ● break and continue work as usual ● you can define else block for for and while loops, they will be executed when the loop terminates normally for n in range(2, 100): for x in range(2, n): if n % x == 0: print "%d == %d * %d" % (n, x, n/x) break else: print "%d is a prime number" % n
  • 15. EXCEPTION HANDLING try: result = x / y except ZeroDivisionError as e: print "y should not be 0!" except: traceback.print_exc() else: print "x / y =", result finally: print "we're in finally block"
  • 16. FUNCTIONS def fname(*args, **kwargs): # function body return returnvalue No function/method overloading, but argument list can vary: def example(a, b=12, c=False): return b if c else a >>> example(42) 42 >>> example(1, 20) 1 >>> example(1, 2, True) 2 >>> example(1, c=True) 12
  • 17. CLASSES class MyClass(object): a = 42 def say_hello(self, name="World"): print "Hello %s!" % name return self.a def __init__(self, a = None): if a: self.a = a >>> i = MyClass(1) >>> x = i.say_hello("Everyone") Hello Everyone! >>> x 1 ● no private attributes/methods (_, __) ● methods are bound to instances: ● >>> sh = a.say_hello >>> sh <bound method MyClass.say_hello of <...(a)...>>
  • 18. INHERITANCE ● Class A (old) <=> class A(object) (new) ● Don't use the old way, esp. not when considering multiple inheritance. class MyClass(BC1, BC2, BC3): def __init__(self): if wrongway: BC1.__init__(self) BC2.__init__(self) BC3.__init__(self) else: super(MyClass, self).__init__() ● method lookup order is well defined (BC1, BC1 bases, BC2, BC2 bases, ...)
  • 19. MODULES, PACKAGES ● Module = file ● Package = directory containing __init__.py Importing a module/package: import os # the whole os package import os.path # the os.path module # the os.path.join function import os.path.join as pathjoin # everything imported into the current namespace from sys import * # do not do this!
  • 20. PYTHON 3 ● some backward incompatible changes: ○ print statement -> print() function ○ b"..." for bytes, "..." for (unicode) strings ○ 1/2 = 0.5 ○ classic classes removed ○ int/long -> int ○ ... lot of smaller changes/improvements ● standardization is not yet finalized ● libraries migrate quite slowly