際際滷

際際滷Share a Scribd company logo
Charming Python
 An introductory session on the Python
        programming language!
Python: A quick look!
Python is a programming language that lets you work more
quickly and integrate your systems more e鍖ectively. You can
learn to use Python and see almost immediate gains in
productivity and lower maintenance costs.

 General Purpose
 High Level
 Interpreted
 Multi paradigm programming
 Fully dynamic typing
 Cross Platform
 CPython, Jython, IronPython (CPython != Cython)
Who uses Python?
  Google, NASA, Facebook ,
  Yahoo!, Microsoft, Oracle,
Nokia, Reddit, Canonical, Walt
    Disney, Astra Zeneca,
          Lucas鍖lm

 All the cool kids are using Python!
Enough Talks!
 Installing and running python codes

*nix and *nix alike system users - sit back and relax!


Windows Users:

 Go to Python.org
 Get the Python 2 installer
 Install it yourself
 Add python to your system path
Show me the codes!
Lets say hello to the big snake!
print "hello python!"

How about a function?

def say_hello(name):
    print "Hello " + name + "!"

say_hello("python")
Let there be Objects!
class TheGreeter:
! def __init__(self, name):
! ! self.name = name


! def greet(self):
! ! print "Hello " + self.name + "!"




greeter = TheGreeter("Python")
greeter.greet()
Python Comments!
"""class TheGreeter:
! def __init__(self, name):
! ! self.name = name


! def greet(self):
! ! print "Hello " + self.name + "!"


"""

greeter = TheGreeter("Python")
#greeter.__init__("masnun")
greeter.greet()
Lists!
id_list = [1,2,3,4,5,6,7,8,9,10]
# Indexing
print id_list[1]
# Add to list
id_list.append(11)
print id_list
# Remove from list
id_list.remove(11)
print id_list
# Slicing
new_list = id_list[0:2]
print new_list
# List Comprehension
another_list = [x for x in id_list if x > 5]
print another_list
# All those squares!
print [x**2 for x in id_list]
Introspection at its best!
    using dir(), help() and pydoc
Conditions and For Loop
In the case of the unforgivable curses!


spell_list= ["Crucio!", "Avada Kedavra!","Imperio!",
"Expelliarmus!"]

for spell in spell_list:
    if spell == "Avada Kedavra!":
    ! print "You're dead already!"
    elif spell == "Imperio!":
    ! print "You lost control of your mind!"
    elif spell == "Crucio!":
    ! print "I can feel your agony!"
    else:
    ! print "No unforgivable curses were cast upon you!"
While Loop
while True:
! print "You're in an infinite loop!"
Using Modules
import math
print math.factorial(999)
Writing Modules
                    lib.py
           def say_hello():
           ! print "Hello Python!"


                  greet.py
          import lib
          lib.say_hello()


And yes, pydoc works on custom modules!
The Python Arsenal!
Notable frameworks, modules and tools!
 Django
 wxWidgets
 PyQT / PySide
 Numpy
 Celery
 Google App Engine
 BeautifulSoup
 Shovel
 Python for Android
 Kivy
The Zen of Python

   import this
import antigravity
PyCharmers & Me!
 PyCharmers: http://pycharmers.net .
 Previously known as Python Bangladesh, a
 platform for Bangladeshi Python developers
 to share and collaborate!

Abu Ashraf Masnun
http://masnun.me | masnun@pycharmers.net | @masnun

Business student, software gardener and open source
enthusiast!
際際滷s & Codes
際際滷s: http://www.masnun.me/talks

Codes: https://github.com/masnun/openday-khulna
Queries?

More Related Content

Charming python

  • 1. Charming Python An introductory session on the Python programming language!
  • 2. Python: A quick look! Python is a programming language that lets you work more quickly and integrate your systems more e鍖ectively. You can learn to use Python and see almost immediate gains in productivity and lower maintenance costs. General Purpose High Level Interpreted Multi paradigm programming Fully dynamic typing Cross Platform CPython, Jython, IronPython (CPython != Cython)
  • 3. Who uses Python? Google, NASA, Facebook , Yahoo!, Microsoft, Oracle, Nokia, Reddit, Canonical, Walt Disney, Astra Zeneca, Lucas鍖lm All the cool kids are using Python!
  • 4. Enough Talks! Installing and running python codes *nix and *nix alike system users - sit back and relax! Windows Users: Go to Python.org Get the Python 2 installer Install it yourself Add python to your system path
  • 5. Show me the codes! Lets say hello to the big snake! print "hello python!" How about a function? def say_hello(name): print "Hello " + name + "!" say_hello("python")
  • 6. Let there be Objects! class TheGreeter: ! def __init__(self, name): ! ! self.name = name ! def greet(self): ! ! print "Hello " + self.name + "!" greeter = TheGreeter("Python") greeter.greet()
  • 7. Python Comments! """class TheGreeter: ! def __init__(self, name): ! ! self.name = name ! def greet(self): ! ! print "Hello " + self.name + "!" """ greeter = TheGreeter("Python") #greeter.__init__("masnun") greeter.greet()
  • 8. Lists! id_list = [1,2,3,4,5,6,7,8,9,10] # Indexing print id_list[1] # Add to list id_list.append(11) print id_list # Remove from list id_list.remove(11) print id_list # Slicing new_list = id_list[0:2] print new_list # List Comprehension another_list = [x for x in id_list if x > 5] print another_list # All those squares! print [x**2 for x in id_list]
  • 9. Introspection at its best! using dir(), help() and pydoc
  • 10. Conditions and For Loop In the case of the unforgivable curses! spell_list= ["Crucio!", "Avada Kedavra!","Imperio!", "Expelliarmus!"] for spell in spell_list: if spell == "Avada Kedavra!": ! print "You're dead already!" elif spell == "Imperio!": ! print "You lost control of your mind!" elif spell == "Crucio!": ! print "I can feel your agony!" else: ! print "No unforgivable curses were cast upon you!"
  • 11. While Loop while True: ! print "You're in an infinite loop!"
  • 12. Using Modules import math print math.factorial(999)
  • 13. Writing Modules lib.py def say_hello(): ! print "Hello Python!" greet.py import lib lib.say_hello() And yes, pydoc works on custom modules!
  • 14. The Python Arsenal! Notable frameworks, modules and tools! Django wxWidgets PyQT / PySide Numpy Celery Google App Engine BeautifulSoup Shovel Python for Android Kivy
  • 15. The Zen of Python import this
  • 17. PyCharmers & Me! PyCharmers: http://pycharmers.net . Previously known as Python Bangladesh, a platform for Bangladeshi Python developers to share and collaborate! Abu Ashraf Masnun http://masnun.me | masnun@pycharmers.net | @masnun Business student, software gardener and open source enthusiast!
  • 18. 際際滷s & Codes 際際滷s: http://www.masnun.me/talks Codes: https://github.com/masnun/openday-khulna

Editor's Notes