SlideShare uma empresa Scribd logo
1 de 26
Baixar para ler offline
1
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
What is Python?
An Introduction
"Perl is worse than Python because people wanted it worse."
- Larry Wall (14 Oct 1998 15:46:10 -0700, Perl Users mailing list)
"Life is better without braces." and "Python fits your brain."
- Bruce Eckel, author of Thinking in C++ , Thinking in Java
"Python is an excellent language [and makes] sensible compromises."
- Peter Norvig (Google), author of Artificial Intelligence
+Wesley Chun, Principal
CyberWeb Consulting
cyberwebconsulting.com
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
Python
is
Fun!
(I've used it at lots of places!)
2
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
I'm here to give
you an idea of
what it is!
(I've written a lot about it!)
3
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
I've taught it at
lots of places!
(companies, schools, etc.)
4
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
About You
SW/HW Engineer/Lead
Sys Admin/IS/IT/Ops
Web/Flash Developer
QA/Testing/Automation
Scientist/Mathematician
Toolsmith, Hobbyist
Release Engineer/SCM
Artist/Designer/UE/UI/UX
Student/Teacher
Familiar with…
Java, C, C++, C#
PHP, JavaScript
(Visual) Basic
Perl, Tcl, Ruby
any other high-
level language…
Django, Pyramid, web2py, Flask, Fabric, Plone, Trac, Mailman, App Engine
5
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
Why are you here? You…
Have heard good word-of-mouth
Came via Django, App Engine, Plone, etc.
Discovered Google, Yahoo!, et al. use it
Already know but want formal training
Were forced by your boss
Safari Books Online: Top 5, Apr 2009
1. iPhone
2. Java
3. Python
4. C#
5. PHP
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
source: TIOBE Programming Community Index for April 2009 (tiobe.com)
6
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
For New Programmers
Programming should be easy enough
to teach like reading & writing (CP4E)
What you need to be good
Some math background
Algebra, physics (problem solving)
Buddy who already is a developer
Even better if they know Python
Tinkerer, curious, itch-scratcher
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
About this Talk
Goal: Introduce as much Python as one can in an hour
Seminar Topics
Language Introduction
Python Object Types
Loops and Conditionals
Files, Functions, Modules
Object-Oriented Programming
Errors and Exception Handling
Miscellaneous
7
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
Background
Guido van Rossum: began late '89, released early '91
Inherits from ABC, Modula, C/C++, LISP, ALGOL, Perl, Java, etc.
Named after Monty Python, not the snake
Cross-platform (Mac, PC, *ix; only need a C compiler)
Alternate implementations: Jython, IronPython, Stackless, PyPy, etc.
Philosophy, Concepts and Syntax
Robust Enough "batteries included" to get job done
Simple Clean, easy-to-read, easier than VB?!?
Modular Plug-n-play, use only what you need
Extensible Can extend language to meet your needs
Intuitive "Python fits your brain."
OOP Object-oriented when you need it (not req'd)
"Pythonic" "There's only one way to do it…."
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
Disadvantages?
Generally slower than
compiled languages
Obscure syntax? Naaah!
Typing requires discipline
Some idiosyncrasies
and required idioms
May not have your feature
Memory management
No marketing force…
mostly word-of-mouth
No world domination… yet!
Why (not) Python?
Advantages
Simple syntax
Rapid development
High-level data structures
Object-oriented
Exception handling
Functional programming
Memory management
Extensible (C/C++/Java)
Many libraries: NW, DB,
GUI, MT, XML/JSON/CSV,
RE, OS/FS, Math, Web;
plus 3rd-party
Community
www.tiobe.com/index.php/
content/paperinfo/tpci
8
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
Built for Non-Programmers
Educational language syntax
Scratch (Tynker, Blockly, App Inventor) , Alice, Python, HTML
Works well for school-aged children
Syntax, memory mgmt, data structures, OOP…
Obstacles to learning concepts, deters interest
Python: retention, morale, understanding
Probably the "best" 1st language
What about professional developers?
C/C++, Java, PHP, Python, Ruby, JavaScript
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
Some Newbie Resources
Published Books
Hello World! Computer Programming for Kids & Other Beginners
(Sande, Sande: 2013)
Invent Your Own Computer Games with Python (Sweigart: 2015)
Python for Kids (Briggs: 2012; see Snake Wrangling for Kids)
Automate the Boring Stuff with Python: Practical Programming for
Total Beginners (Sweigart: 2015)
Learning with Python: How to Think Like a Computer Scientist
(Downey, Elkner, Meyers: 2002)
Online Books, Tutorials, Environments, etc.
How to Think Like a Computer Scientist (Downey, Elkner, Meyers)
Learning to Program (Gauld)
LiveWires Python course
A Byte of Python (Swaroop)
Instant Hacking: Learning to Program with Python (Hetland)
Snake Wrangling for Kids (Briggs)
Computer Programming is Fun! (Handy)
Karel the Robot clones: Guido van Robot, RUR-PLE
9
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
Run Python interactive interpreter from default IDE: IDLE
Or do it from the cmd-line or DOS command shell
$ python # or C:> python
Python 2.7.10 (default, Jul 27 2015, 11:35:10)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> print 'Hello World!'
Hello World!
Interactive Interpreter
To exit: Ctrl-D in IDLE or *ix
cmd line; or Ctrl-Z in DOS
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
What You Just Saw
>>> this is the Python prompt
Enter any Python command after it
Use print to display output to users
Use print() in Python 3
To exit interactive interpreter
Ctrl-D from IDLE or *ix command-line
Ctrl-Z from a DOS/command shell
Interactive Interpreter: testing, debugging, hacking,
experimenting regardless of IDE use or otherwise
10
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
Getting Python
POSIX (Mac OS, *nix): already installed
PC, source, and other downloads
python.org or corepython.com
Other IDEs
SPE (pictured)
PythonWin
Eclipse & PyDev
PyCharm/intelliJ
Komodo
WingIDE
IPython Notebook
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
Online Python interpreters/shells
• Can't or don't wish to install Python locally?
• Run Python from just a web browser
•ideone.com
•colabv6.dan.co.jp/lleval.html
•doc.pyschools.com/console
•repl.it/languages/Python
•skulpt.org (pure JS implementation; allows turtle)
•pythonwebconsole.thomnichols.org
•shell.appspot.com (Google App Engine + libraries)
•codepad.org
•lotrepls.appspot.com
•datamech.com/devan/trypython/trypython.py
• Most are 2.x, some (top pair) do 3.x
• Some support multiple languages
11
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
Online learning systems
•Learn & code Python with these learning environments
•Codecademy
•codecademy.com/tracks/python
•PySchools
•pyschools.com
•Online Python Tutor
•pythontutor.com
•Online Python course
•Udacity
•udacity.com/course/cs101
•Coursera
•coursera.org/course/interactivepython
•coursera.org/course/programming1
•LearnPython.org
•learnpython.org
•CodingBat (login optional)
•codingbat.com/python
•SingPath (login required)
•singpath.com
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
Hello World!
Using print statement or function
print 'Hello World!' # 2.x
print('Hello World!') # 3.x
Or for 3.x compatibility & "futureproofing:"
from __future__ import print_function
# works in both 2.x and 3.x
print('Hello World!')
12
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
Common Beginner Gotchas
Code delimited by indentation not braces { }
if x > 10:
return "'x' is greater than 10"
else:
return "'x' is less than 10"
No extraneous characters ( ; , $, ……)
No switch-case, private class members, ++/--,
static type checking, anonymous blocks, etc.
Freaky-looking floats*: 1.1 1.10000000001
Single element tuple needs comma: (None,)
3.x-only: print() & true div: 1/2 == 0.5
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
Variables and Expressions
>>> 4 + 6 * 5 # math ops like other langs
34
>>> a = 4 + 6 ** 2 # no declaration needed
>>> a
40
>>> a = 'Python' # auto garbage collection
>>> b = 'is cool'
>>> a + b # ops can be overloaded
'Pythonis cool'
>>> a = a + ' ' + b # reassignment no problem
>>> a
'Python is cool'
>>> # useful interactive tool
13
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
Objects
Standard Data Types
Numbers (3-8)
Strings (2-3)
Lists
Tuples
Dictionaries
Sets (2)
Other Types
None
Files, Modules
Functions/Methods
Iterators/Generators
Type/Classes
miscellaneous
Allocated on assignment: Dynamic/Duck Typing
Memory Management: Reference Counting
Variables not declared: type inferred on assignment
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
Standard Operators
+ - * / // % **
<< >> & | ^ ~
== >= <= < > !=
is is not and or not
•Grouping expressions in ( ) okay as usual
•** means exponentiation, % means modulus/remainder
•/ means true division in 3.x and classic division in 2.x
•Use // for standard integer floor division
•Assignment using single equals ( = )
•Augmented assignment +=, -=, *=, etc. (no ++ though)
14
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
Numbers
integers (no size limit except for VM)
-680, 0o237, 0xDEADBEEF, 64-0x41, 0b110
floating point real numbers (IEEE-754 C double)
-97.65, -3.14159, -6e2, 0.1
complex numbers
Composed of real and imaginary parts (floats)
11.65-5.55J, 4J, -3e2+8.73J, 0.1-2.3e4J
Also long, bool, Decimal, Fraction, Rational, etc.
Other modules: math, cmath, random, operator
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
Strings ' ' " " ''' '''
Strings are sequences of characters (single/double quotes)
No 'char' type… strings of length 1
Format operator ( % ) for printf()-like functionality
Flexible alternative: string format() method (new in 2.6)
Triple quotes allow special characters like newlines
>>> x = 'Python'
>>> x * 2
'PythonPython'
>>> x *= 2
>>> x
'PythonPython'
>>> x[-1]
'n'
>>> x[-4:-1]
'tho'
>>> 'ton' in x
False
>>> '%s is number %d' % (x[:6], 1)
'Python is number 1'
>>> '{0} is #{1}'.format(x[:6], 1)
'Python is #1'
>>>
>>> hi = '''hi
there'''
>>> hi
'hinthere'
>>> print(hi)
hi
there
15
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
Lists [ ] and Tuples ( )
Lists: ordered sequences of arbitrary objects
Mutable (values can be updated)
Can have lists of lists, i.e., multidimensional indexing
Tuples similar but immutable (no value updates allowed)
"List comprehensions" allows for quick logical building of lists
Common list methods:
list.sort() # "sort" list contents in-place
list.reverse() # reverse a list in-place
list.append() # append item to list
list.insert() # insert items in list
list.remove/pop() # remove item(s) from list
list.extend() # extend a list with another one
list.count() # return number of item occurrences
list.index() # lowest index where item is found
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
List Operations
>>> m = ['Core', 'Programming', 9, 2006]
>>> m.append('Prentice Hall')
>>> m.insert(1, 'Pytho')
>>> m
['Core', 'Pytho', 'Programming', 9, 2006, 'Prentice Hall']
>>> m[1] = 'Python'
>>> m.pop(3)
9
>>> m
['Core', 'Python', 'Programming', 2006, 'Prentice Hall']
>>> m.sort()
>>> m
[2006, 'Core', 'Prentice Hall', 'Programming', 'Python']
>>> [i*3 for i in range(20) if i % 2 == 0]
[0, 6, 12, 18, 24, 30, 36, 42, 48, 54]
>>> f = open('myFile', 'r')
>>> data = [line.strip() for line in f]
>>> f.close()
16
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
Dictionaries { }
Dictionaries (sets like dicts but only hashed keys)
Mutable, resizable hash tables
Mappings of keys to values
Keys: scalar (usually strings or numbers)
Values: arbitrary Python objects
No key collisions allowed
Similar to Java HashMap, JS Object, Perl hash/associative array
Most commonly-used methods:
d.items() # iterable: key-value pairs
d.get() # return key's value (or default)
d.setdefault() # return key's value, set if nec.
d.pop() # remove item from d and return
d.update() # merge contents from another dict
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
Dictionary Operations
>>> d = {'title': 'Core Python Programming', 'year': 2006}
>>> d
{'year': 2006, 'title': 'Core Python Programming'}
>>> 'year' in d
True
>>> 'pub' in d
False
>>> d.get('pub', 'N/A') # KeyError if d['pub']
'N/A'
>>> d['pub'] = 'Prentice Hall'
>>> d.get('pub', 'N/A') # no KeyError for d['pub'] now
'Prentice Hall'
>>> for eachKey in d:
print(eachKey, ':', d[eachKey])
year : 2006
pub : Prentice Hall
title : Core Python Programming
17
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
if-elif-else Statements
Conditional statements are what you expect
# prompt, get, and check user input
data = raw_input("Enter 'y' or 'n': ")
if data[0] == 'y':
print("You typed 'y'.") # 'y' key
elif data[0] == 'n':
print("You typed 'n'.") # 'n' key
else:
print('invalid key!') # other key
Ternary Operator (aka Conditional Expressions: C ? T : F)
smaller = x if x < y else y # T if C else F
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
Loops
Python while loops are same as in other languages
for more like shell foreach & used ~90% over while
Iterate over elements rather than counting/conditional
range() helps "simulate" traditional for loops
Loop "friends" break & continue also here
aList = [123, 'xyz', 45.67]
>>> for eachItem in aList:
... print(eachItem)
123
xyz
45.67
>>> for i in range(0, 3, 1): # think "for (i=0; i<3; i+=1)"
... print(i)
0
1
2
>>> i = 0
>>> while i < 3:
... print(i)
... i += 1
0
1
2
18
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
Open a file and get back a file object
f = open(name, mode) # mode: r/r+, w, a, U
Most commonly-used file methods
f.close() Close file
f.read() Read bytes from file
f.write() Write a string to file
Display text file example:
f = open('data.txt', 'r')
for line in f:
print(line.rstrip())
f.close()
… or, alternatively, more modern Python (2.6+)
with open('data.txt', 'r') as f:
for line in f:
print(line, end='')
Files
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
Function declaration syntax and example
def func_name([v1,…, vN=dv,… *args, **kwargs):
"documentation string"
function_body
def addYor10(x, y=10): # 'y' has default value
"adds 'x' and 'y'; latter defaults to 10"
return x + y
Functions heterogenous (untyped)
Default values & variable arguments supported
Can return 0, 1, or more objects
Python returns None if no return value provided
Introducing Functions
19
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
Importing Modules & Attributes
Importing modules or packages using import statement
import module_name
import string
num = string.atoi('123')
Importing module attributes using from-import statement
Names brought into (global) variable namespace
from module_name import module_element
from string import atoi
num = atoi('123')
Packages: allow for organizing modules using the file system
Use int()though…
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
Standard Library Sampler (“B.I.”)
API for SQLite databasessqlite3
Email processingemail, {smtp,pop,imap}lib
External process managementsubprocess
Data compression and archive filesgzip, bz2, zipfile, tarfile
Various Internet client libraries{ftp,url,http,*}lib
Serialize Python objectspickle, cPickle, shelve
Various math/numberic processing{c,}math, random, fractions,……
High-level threads/multiprocess APIsthreading, multiprocessing
Python/Tk GUI toolkit interfaceTkinter
Socket interface & server classes (TCP, UDP)socket, SocketServer
Date and time constants and functionstime, datetime, calendar
Text processingre, csv, json, xml
Operating and file system interfaceos and os.path
System data, processing, and functionalitysys
DescriptionModule Name(s)
20
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
Programmer Tools
Debugger
pdb
Profilers
profile
hotshot
cProfile
Tracer/Tracker
trace
Logger
logging
Timer
timeit
Help/Documentation
pydoc
Testing
unittest
doctest
(external) nose
(external) py.test
Testing tools taxonomy
goo.gl/Fpz0Z
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
Object-Oriented Programming
"Constructor"/Initializer is __init__(), "self" is "this"
Class instantiation via function interface (rather than "new")
Instance attrs, multiple inheritance; no overloading nor private
class MyClass(object):
... def __init__(self, data=2):
... self.info = data
... def times(self, x):
... return "%d * %d is %d" % (
... self.info, x, self.info * x)
>>>
>>> inst = MyClass(21)
>>> inst.info
21
>>> print inst.times(3)
21 * 3 is 63
21
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
Exceptions and try-except
Exception handling via try-except statement
try:
# statements to monitor
except ExceptionName as e:
# code to exec if ExceptionName occurs
try:
f = open('data.txt', 'r')
except IOError as e:
print("Can't open file:", e)
return False # or sys.exit(1), etc.
Throw exceptions with raise; there is also a finally
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
Python 2 vs. Python 3
The What and the Why
Fix early design flaws
Some new features, many small improvements
Plan: develop (remainder of) 2.x and 3.x together
Provide transition tools (2to3, 2.6+, -Q, -3)
Key Updates (no major syntax changes)
print, exec changed to functions
True division: 1/2 == 0.5
Performance (more iterators, fewer lists)
Consolidation/unification (integers, classes)
Strings: Unicode default; bytes/bytearray types
Intro to Python 3 article FYI
informit.com/articles/article.aspx?p=1328795
22
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
Where do you go from here?
•The tip of the iceberg…
System Administration scripting tools and automation
Networked/Internet Client-Server systems
Graphical User Interface (GUI) design and development
Web frameworks and rich Internet applications (RIA)
Scientific/numeric/mathematics-centric development
Database programming, Object-Relational Mappers (ORMs)
XML, JSON, CSV and other forms of text processing
Java with Jython; .NET/Mono with IronPython; COM, MFC
Graphics/imaging/multimedia/visual art processing
Multithreaded and higher-performance applications
Embedded system design (hardware as well as Python)
QA/Testing automated test tools, suites, and frameworks
Rapid application prototyping (all application areas)
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
Additional Resources
Books for programmers (more @ goo.gl/i4u0R)
Quick Python Book (2010)
Python Fundamentals LiveLessons DVD (Chun, 2009)
Core Python Programming (2006 [2009])
Dive into Python (2009, 2004)
Beginning Python: From Novice to Professional (2008)
Python Cookbook (2013, 2005)
Python Standard Library by Example (2011)
Python Essential Reference (2009) & Python in a Nutshell (2006)
Some online resources
Python Quick Reference Guide rgruet.free.fr#QuickRef
Python Conferences worldwide www.pycon.org
Core Python Programming corepython.com
Mailing list/newsgroup groups.google.com/group/comp.lang.python
Python Docs (+ FAQ, tutorial,…) docs.python.org
External 3rd-party/ repo python.org/pypi
23
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
1. Beautiful is better than ugly.
2. Explicit is better than implicit.
3. Simple is better than complex.
4. Complex is better than complicated.
5. Flat is better than nested.
6. Sparse is better than dense.
7. Readability counts.
8. Special cases aren't special enough to break the rules.
9. Although practicality beats purity.
10. Errors should never pass silently.
11. Unless explicitly silenced.
12. In the face of ambiguity, refuse the temptation to guess.
13. There should be one — and preferably only one — obvious way to do it.
14. Although that way may not be obvious at first unless you're Dutch.
15. Now is better than never.
16. Although never is often better than right now.
17. If the implementation is hard to explain, it's a bad idea.
18. If the implementation is easy to explain, it may be a good idea.
19. Namespaces are one honking great idea — let's do more of those!
The Zen of Python (or import this by Tim Peters)
(c) 1998-2015 CyberWeb Consulting.
All rights reserved.
Thank you! Questions?
+Wesley Chun # Google+
@wescpy # Twitter
wescpy@gmail.com # e-mail
corepython.com # books
cyberwebconsulting.com # training
wescpy.blogspot.com # Python blog
wesc.livejournal.com # personal blog
THE COMPLETE DEVELOPER'S GUIDE TO PYTHON
• New to Python? The definitive guide to Python development for
experienced programmers
• Covers core language features thoroughly, including those found in
the latest Python releases — learn more than just the syntax!
• Learn advanced topics such as regular expressions, networking,
multithreading, GUI, Web/CGI, and Python extensions
• Includes brand-new material on databases, Internet clients, Java/Jython,
and Microsoft Office, plus Python 2.6 and 3
• Presents hundreds of code snippets, interactive examples, and practical
exercises to strengthen your Python skills
Python is an agile, robust, expressive, fully object-oriented, extensible, and
scalable programming language. It combines the power of compiled languages
with the simplicity and rapid development of scripting languages. In Core
Python Programming, Second Edition, leading Python developer and trainer
Wesley Chun helps you learn Python quickly and comprehensively so that
you can immediately succeed with any Python project.
Using practical code examples, Chun introduces all the fundamentals of
Python programming: syntax, objects and memory management, data types,
operators, files and I/O, functions, generators, error handling and exceptions,
loops, iterators, functional programming, object-oriented programming and
more. After you learn the core fundamentals of Python, he shows you what
you can do with your new skills, delving into advanced topics, such as regular
expressions, networking programming with sockets, multithreading, GUI
development, Web/CGI programming and extending Python in C.
This edition reflects major enhancements in the Python 2.x series, including 2.6
and tips for migrating to 3. It contains new chapters on database and Internet client
programming, plus coverage of many new topics, including new-style classes, Java
and Jython, Microsoft Office (Win32 COM Client) programming, and much more.
• Learn professional Python style, best practices, and good programming habits
• Gain a deep understanding of Python's objects and memory model as well
as its OOP features, including those found in Python's new-style classes
• Build more effective Web, CGI, Internet, and network and other client/
server applications
• Learn how to develop your own GUI applications using Tkinter and other
toolkits available for Python
• Improve the performance of your Python applications by writing extensions
in C and other languages, or enhance I/O-bound applications by using
multithreading
• Learn about Python's database API and how to use a variety of database
systems with Python, including MySQL, Postgres, and SQLite
• Features appendices on Python 2.6 & 3, including tips on migrating to the
next generation!
Core Python Programming
Second Edition
"The long-awaited second
edition of Wesley Chun's
Core Python Programming
proves to be well worth the
wait–its deep and broad
coverage and useful exercises
will help readers learn and
practice good Python."
— ALEX MARTELLI,
author of Python in a Nutshell and
editor of Python Cookbook
"There has been lot of good
buzz around Wesley Chun's
Core Python Programming.
It turns out that all the buzz is
well earned. I think this is the
best book currently available
for learning Python. I would
recommend Chun's book over
Learning Python (O'Reilly),
Programming Python
(O'Reilly), or The Quick Python
Book (Manning)."
— DAVID MERTZ, Ph.D.,
IBM DeveloperWorks®
"Finally, a book good enough
to be both a textbook and
a reference on the Python
language now exists."
— MICHAEL BAXTER,
Linux Journal
Wesley Chun
FOR MORE INFORMATION PLEASE VISIT:
informit.com/python
Available wherever technical books are sold.
AVAILABLE
• BOOK: 9780132269933
• SAFARI ONLINE
• E-BOOK: 9780137060566
• SONY: 9780137061259
SAVE up to 40%
Buy 1 Save 35% | Buy 2
or More and Save 40%
Use discount code:
PYTHONCENTER at
informit.com/python
Other titles by
Wesley Chun
FOR MORE INFORMATION PLEASE VISIT:
informit.com/python
Available wherever technical books are sold.
SAVE up to 40%
Buy 1 Save 35% | Buy 2
or More and Save 40%
Use discount code:
PYTHONCENTER at
informit.com/python
About the Author
WESLEY J. CHUN, MSCS, is the author of Python Fundamentals, a companion
video to Core Python Programming, and the coauthor of Python Web Development
with Django. In addition to being a senior software architect, he runs CyberWeb
(cyberwebconsulting.com), a consulting business specializing in Python software
engineering and technical training. He has more than twenty-five years of
programming, teaching, and writing experience, including more than a decade
with Python. While at Yahoo!, he helped create Yahoo!Mail and Yahoo! People
Search using Python. He holds degrees in computer science, mathematics, and
music from the University of California.
Python Web Development with Django
JEFF FORCIER, PAUL BISSEX, WESLEY CHUN | ISBN: 9780132356138
Using the simple, robust, Python-based Django framework, you can build powerful
Web solutions with remarkably few lines of code. In Python Web Development with
Django®, three experienced Django and Python developers cover all the techniques,
tools, and concepts you need to make the most of Django 1.0, including all the major
features of the new release.
The authors teach Django through in-depth explanations, plus provide extensive
sample code supported with images and line-by-line explanations. You’ll discover
how Django leverages Python’s development speed and flexibility to help you solve
a wide spectrum of Web development problems and learn Django best practices
covered nowhere else. You’ll build your first Django application in just minutes and
deepen your real-world skills through start-to-finish application projects.
Python Fundamentals (Video Training)
WESLEY CHUN | ISBN: 9780137143412
FOR ANY STUDENT OR PROFESSIONAL INTERESTED IN
LEARNING THE FUNDAMENTALS OF PYTHON
In this one-of-a-kind video package, leading Python developer and trainer Wesley
Chun helps you learn Python quickly and comprehensively, so that you can
immediately succeed with any Python project.
Just click and watch: One step at a time, you will master Python fundamentals.
If you already have Python experience, these videos will help further develop
your skills. The lessons start with an introduction to the core features of the
Python language, including syntax basics and standard types and operations.
The lessons progress into advanced topics, such as Python’s memory model and
object-oriented programming.

Mais conteúdo relacionado

Mais procurados

Intro to Python Workshop San Diego, CA (January 19, 2013)
Intro to Python Workshop San Diego, CA (January 19, 2013)Intro to Python Workshop San Diego, CA (January 19, 2013)
Intro to Python Workshop San Diego, CA (January 19, 2013)Kendall
 
Chapter 8 getting started with python
Chapter 8 getting started with pythonChapter 8 getting started with python
Chapter 8 getting started with pythonPraveen M Jigajinni
 
Python Scripting Tutorial for Beginners | Python Tutorial | Python Training |...
Python Scripting Tutorial for Beginners | Python Tutorial | Python Training |...Python Scripting Tutorial for Beginners | Python Tutorial | Python Training |...
Python Scripting Tutorial for Beginners | Python Tutorial | Python Training |...Edureka!
 
11 Unit1 Chapter 1 Getting Started With Python
11   Unit1 Chapter 1 Getting Started With Python11   Unit1 Chapter 1 Getting Started With Python
11 Unit1 Chapter 1 Getting Started With PythonPraveen M Jigajinni
 
Using SWIG to Control, Prototype, and Debug C Programs with Python
Using SWIG to Control, Prototype, and Debug C Programs with PythonUsing SWIG to Control, Prototype, and Debug C Programs with Python
Using SWIG to Control, Prototype, and Debug C Programs with PythonDavid Beazley (Dabeaz LLC)
 
SWIG : An Easy to Use Tool for Integrating Scripting Languages with C and C++
SWIG : An Easy to Use Tool for Integrating Scripting Languages with C and C++SWIG : An Easy to Use Tool for Integrating Scripting Languages with C and C++
SWIG : An Easy to Use Tool for Integrating Scripting Languages with C and C++David Beazley (Dabeaz LLC)
 
Python @ PiTech - March 2009
Python @ PiTech - March 2009Python @ PiTech - March 2009
Python @ PiTech - March 2009tudorprodan
 
web programming Unit VIII complete about python by Bhavsingh Maloth
web programming Unit VIII complete about python  by Bhavsingh Malothweb programming Unit VIII complete about python  by Bhavsingh Maloth
web programming Unit VIII complete about python by Bhavsingh MalothBhavsingh Maloth
 
Python for the Mobile and Web
Python for the Mobile and WebPython for the Mobile and Web
Python for the Mobile and WebDerek Kiong
 
1901200100000 presentation short term mini project on python
1901200100000 presentation short term mini project on python1901200100000 presentation short term mini project on python
1901200100000 presentation short term mini project on pythonSANTOSHJAISWAL52
 
Getting started with Linux and Python by Caffe
Getting started with Linux and Python by CaffeGetting started with Linux and Python by Caffe
Getting started with Linux and Python by CaffeLihang Li
 

Mais procurados (18)

Python Introduction
Python IntroductionPython Introduction
Python Introduction
 
Intro to Python Workshop San Diego, CA (January 19, 2013)
Intro to Python Workshop San Diego, CA (January 19, 2013)Intro to Python Workshop San Diego, CA (January 19, 2013)
Intro to Python Workshop San Diego, CA (January 19, 2013)
 
Chapter 8 getting started with python
Chapter 8 getting started with pythonChapter 8 getting started with python
Chapter 8 getting started with python
 
Python Scripting Tutorial for Beginners | Python Tutorial | Python Training |...
Python Scripting Tutorial for Beginners | Python Tutorial | Python Training |...Python Scripting Tutorial for Beginners | Python Tutorial | Python Training |...
Python Scripting Tutorial for Beginners | Python Tutorial | Python Training |...
 
11 Unit1 Chapter 1 Getting Started With Python
11   Unit1 Chapter 1 Getting Started With Python11   Unit1 Chapter 1 Getting Started With Python
11 Unit1 Chapter 1 Getting Started With Python
 
Using SWIG to Control, Prototype, and Debug C Programs with Python
Using SWIG to Control, Prototype, and Debug C Programs with PythonUsing SWIG to Control, Prototype, and Debug C Programs with Python
Using SWIG to Control, Prototype, and Debug C Programs with Python
 
Python Introduction
Python IntroductionPython Introduction
Python Introduction
 
Python - the basics
Python - the basicsPython - the basics
Python - the basics
 
SWIG : An Easy to Use Tool for Integrating Scripting Languages with C and C++
SWIG : An Easy to Use Tool for Integrating Scripting Languages with C and C++SWIG : An Easy to Use Tool for Integrating Scripting Languages with C and C++
SWIG : An Easy to Use Tool for Integrating Scripting Languages with C and C++
 
Basics of python
Basics of pythonBasics of python
Basics of python
 
Python tutorial
Python tutorialPython tutorial
Python tutorial
 
Python tutorial
Python tutorialPython tutorial
Python tutorial
 
Python @ PiTech - March 2009
Python @ PiTech - March 2009Python @ PiTech - March 2009
Python @ PiTech - March 2009
 
web programming Unit VIII complete about python by Bhavsingh Maloth
web programming Unit VIII complete about python  by Bhavsingh Malothweb programming Unit VIII complete about python  by Bhavsingh Maloth
web programming Unit VIII complete about python by Bhavsingh Maloth
 
Python for the Mobile and Web
Python for the Mobile and WebPython for the Mobile and Web
Python for the Mobile and Web
 
1901200100000 presentation short term mini project on python
1901200100000 presentation short term mini project on python1901200100000 presentation short term mini project on python
1901200100000 presentation short term mini project on python
 
Getting started with Linux and Python by Caffe
Getting started with Linux and Python by CaffeGetting started with Linux and Python by Caffe
Getting started with Linux and Python by Caffe
 
Lets learn Python !
Lets learn Python !Lets learn Python !
Lets learn Python !
 

Destaque

G Suite & Google APIs coding workshop
G Suite & Google APIs coding workshopG Suite & Google APIs coding workshop
G Suite & Google APIs coding workshopwesley chun
 
Exploring Google APIs with Python
Exploring Google APIs with PythonExploring Google APIs with Python
Exploring Google APIs with Pythonwesley chun
 
Power & flexibility of the Google Sheets API
Power & flexibility of the Google Sheets APIPower & flexibility of the Google Sheets API
Power & flexibility of the Google Sheets APIwesley chun
 
Google Cloud Platform & APIs Overview
Google Cloud Platform & APIs OverviewGoogle Cloud Platform & APIs Overview
Google Cloud Platform & APIs Overviewwesley chun
 
Power your apps with Gmail, Google Drive, Calendar, Sheets, Slides, Apps Scri...
Power your apps with Gmail, Google Drive, Calendar, Sheets, Slides, Apps Scri...Power your apps with Gmail, Google Drive, Calendar, Sheets, Slides, Apps Scri...
Power your apps with Gmail, Google Drive, Calendar, Sheets, Slides, Apps Scri...wesley chun
 
What is the Google Cloud Platform?
What is the Google Cloud Platform?What is the Google Cloud Platform?
What is the Google Cloud Platform?wesley chun
 
Coding Google... you can do it!
Coding Google... you can do it!Coding Google... you can do it!
Coding Google... you can do it!wesley chun
 
Exploring Google APIs with Python & JavaScript
Exploring Google APIs with Python & JavaScriptExploring Google APIs with Python & JavaScript
Exploring Google APIs with Python & JavaScriptwesley chun
 

Destaque (9)

G Suite & Google APIs coding workshop
G Suite & Google APIs coding workshopG Suite & Google APIs coding workshop
G Suite & Google APIs coding workshop
 
Exploring Google APIs with Python
Exploring Google APIs with PythonExploring Google APIs with Python
Exploring Google APIs with Python
 
What is Python?
What is Python?What is Python?
What is Python?
 
Power & flexibility of the Google Sheets API
Power & flexibility of the Google Sheets APIPower & flexibility of the Google Sheets API
Power & flexibility of the Google Sheets API
 
Google Cloud Platform & APIs Overview
Google Cloud Platform & APIs OverviewGoogle Cloud Platform & APIs Overview
Google Cloud Platform & APIs Overview
 
Power your apps with Gmail, Google Drive, Calendar, Sheets, Slides, Apps Scri...
Power your apps with Gmail, Google Drive, Calendar, Sheets, Slides, Apps Scri...Power your apps with Gmail, Google Drive, Calendar, Sheets, Slides, Apps Scri...
Power your apps with Gmail, Google Drive, Calendar, Sheets, Slides, Apps Scri...
 
What is the Google Cloud Platform?
What is the Google Cloud Platform?What is the Google Cloud Platform?
What is the Google Cloud Platform?
 
Coding Google... you can do it!
Coding Google... you can do it!Coding Google... you can do it!
Coding Google... you can do it!
 
Exploring Google APIs with Python & JavaScript
Exploring Google APIs with Python & JavaScriptExploring Google APIs with Python & JavaScript
Exploring Google APIs with Python & JavaScript
 

Semelhante a What is Python? (Silicon Valley CodeCamp 2015)

Python and its Applications
Python and its ApplicationsPython and its Applications
Python and its ApplicationsAbhijeet Singh
 
Pythonanditsapplications 161121160425
Pythonanditsapplications 161121160425Pythonanditsapplications 161121160425
Pythonanditsapplications 161121160425Sapna Tyagi
 
Python on a chip
Python on a chipPython on a chip
Python on a chipstoggi
 
Python_final_print_batch_II_vision_academy.pdf
Python_final_print_batch_II_vision_academy.pdfPython_final_print_batch_II_vision_academy.pdf
Python_final_print_batch_II_vision_academy.pdfbhagyashri686896
 
Python_final_print_batch_II_vision_academy (1).pdf
Python_final_print_batch_II_vision_academy (1).pdfPython_final_print_batch_II_vision_academy (1).pdf
Python_final_print_batch_II_vision_academy (1).pdfrupaliakhute
 
Python_final_print_batch_II_vision_academy.pdf
Python_final_print_batch_II_vision_academy.pdfPython_final_print_batch_II_vision_academy.pdf
Python_final_print_batch_II_vision_academy.pdfsannykhopade
 
Python_vision_academy notes
Python_vision_academy notes Python_vision_academy notes
Python_vision_academy notes rajaniraut
 
Python programming language introduction unit
Python programming language introduction unitPython programming language introduction unit
Python programming language introduction unitmichaelaaron25322
 
Py4 inf 01-intro
Py4 inf 01-introPy4 inf 01-intro
Py4 inf 01-introIshaq Ali
 
POWER OF PYTHON PROGRAMMING LANGUAGE
POWER OF PYTHON PROGRAMMING LANGUAGE POWER OF PYTHON PROGRAMMING LANGUAGE
POWER OF PYTHON PROGRAMMING LANGUAGE teachersduniya.com
 
Python and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthroughPython and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthroughgabriellekuruvilla
 
Python_final_print_vison_academy_9822506209.pdf
Python_final_print_vison_academy_9822506209.pdfPython_final_print_vison_academy_9822506209.pdf
Python_final_print_vison_academy_9822506209.pdfVisionAcademyProfSac
 
Python intro
Python introPython intro
Python introrik0
 
python programming.pptx
python programming.pptxpython programming.pptx
python programming.pptxKaviya452563
 
Behold the Power of Python
Behold the Power of PythonBehold the Power of Python
Behold the Power of PythonSarah Dutkiewicz
 

Semelhante a What is Python? (Silicon Valley CodeCamp 2015) (20)

Python and its Applications
Python and its ApplicationsPython and its Applications
Python and its Applications
 
Pythonanditsapplications 161121160425
Pythonanditsapplications 161121160425Pythonanditsapplications 161121160425
Pythonanditsapplications 161121160425
 
Python on a chip
Python on a chipPython on a chip
Python on a chip
 
Python_final_print_batch_II_vision_academy.pdf
Python_final_print_batch_II_vision_academy.pdfPython_final_print_batch_II_vision_academy.pdf
Python_final_print_batch_II_vision_academy.pdf
 
Python_final_print_batch_II_vision_academy (1).pdf
Python_final_print_batch_II_vision_academy (1).pdfPython_final_print_batch_II_vision_academy (1).pdf
Python_final_print_batch_II_vision_academy (1).pdf
 
Python_final_print_batch_II_vision_academy.pdf
Python_final_print_batch_II_vision_academy.pdfPython_final_print_batch_II_vision_academy.pdf
Python_final_print_batch_II_vision_academy.pdf
 
Python_vision_academy notes
Python_vision_academy notes Python_vision_academy notes
Python_vision_academy notes
 
Python programming language introduction unit
Python programming language introduction unitPython programming language introduction unit
Python programming language introduction unit
 
Py4 inf 01-intro
Py4 inf 01-introPy4 inf 01-intro
Py4 inf 01-intro
 
POWER OF PYTHON PROGRAMMING LANGUAGE
POWER OF PYTHON PROGRAMMING LANGUAGE POWER OF PYTHON PROGRAMMING LANGUAGE
POWER OF PYTHON PROGRAMMING LANGUAGE
 
Python and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthroughPython and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthrough
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Python_final_print_vison_academy_9822506209.pdf
Python_final_print_vison_academy_9822506209.pdfPython_final_print_vison_academy_9822506209.pdf
Python_final_print_vison_academy_9822506209.pdf
 
Python intro
Python introPython intro
Python intro
 
python programming.pptx
python programming.pptxpython programming.pptx
python programming.pptx
 
05 python.pdf
05 python.pdf05 python.pdf
05 python.pdf
 
Behold the Power of Python
Behold the Power of PythonBehold the Power of Python
Behold the Power of Python
 
what is python ?
what is python ? what is python ?
what is python ?
 
Python Programming Draft PPT.pptx
Python Programming Draft PPT.pptxPython Programming Draft PPT.pptx
Python Programming Draft PPT.pptx
 
What is Python?
What is Python?What is Python?
What is Python?
 

Mais de wesley chun

Easy path to machine learning (2023-2024)
Easy path to machine learning (2023-2024)Easy path to machine learning (2023-2024)
Easy path to machine learning (2023-2024)wesley chun
 
Powerful Google developer tools for immediate impact! (2023-24 B)
Powerful Google developer tools for immediate impact! (2023-24 B)Powerful Google developer tools for immediate impact! (2023-24 B)
Powerful Google developer tools for immediate impact! (2023-24 B)wesley chun
 
Exploring Google APIs with Python
Exploring Google APIs with PythonExploring Google APIs with Python
Exploring Google APIs with Pythonwesley chun
 
Serverless computing with Google Cloud (2023-24)
Serverless computing with Google Cloud (2023-24)Serverless computing with Google Cloud (2023-24)
Serverless computing with Google Cloud (2023-24)wesley chun
 
Powerful Google developer tools for immediate impact! (2023-24 A)
Powerful Google developer tools for immediate impact! (2023-24 A)Powerful Google developer tools for immediate impact! (2023-24 A)
Powerful Google developer tools for immediate impact! (2023-24 A)wesley chun
 
Build an AI/ML-driven image archive processing workflow: Image archive, analy...
Build an AI/ML-driven image archive processing workflow: Image archive, analy...Build an AI/ML-driven image archive processing workflow: Image archive, analy...
Build an AI/ML-driven image archive processing workflow: Image archive, analy...wesley chun
 
Exploring Google APIs 102: Cloud vs. non-GCP Google APIs
Exploring Google APIs 102: Cloud vs. non-GCP Google APIsExploring Google APIs 102: Cloud vs. non-GCP Google APIs
Exploring Google APIs 102: Cloud vs. non-GCP Google APIswesley chun
 
Serverless Computing with Python
Serverless Computing with PythonServerless Computing with Python
Serverless Computing with Pythonwesley chun
 
Easy path to machine learning (2022)
Easy path to machine learning (2022)Easy path to machine learning (2022)
Easy path to machine learning (2022)wesley chun
 
Google... more than just a cloud
Google... more than just a cloudGoogle... more than just a cloud
Google... more than just a cloudwesley chun
 
Accessing Google Cloud APIs
Accessing Google Cloud APIsAccessing Google Cloud APIs
Accessing Google Cloud APIswesley chun
 
Serverless computing with Google Cloud
Serverless computing with Google CloudServerless computing with Google Cloud
Serverless computing with Google Cloudwesley chun
 
Serverless Computing with Google Cloud
Serverless Computing with Google CloudServerless Computing with Google Cloud
Serverless Computing with Google Cloudwesley chun
 
Designing flexible apps deployable to App Engine, Cloud Functions, or Cloud Run
Designing flexible apps deployable to App Engine, Cloud Functions, or Cloud RunDesigning flexible apps deployable to App Engine, Cloud Functions, or Cloud Run
Designing flexible apps deployable to App Engine, Cloud Functions, or Cloud Runwesley chun
 
Image archive, analysis & report generation with Google Cloud
Image archive, analysis & report generation with Google CloudImage archive, analysis & report generation with Google Cloud
Image archive, analysis & report generation with Google Cloudwesley chun
 
Easy path to machine learning (Spring 2021)
Easy path to machine learning (Spring 2021)Easy path to machine learning (Spring 2021)
Easy path to machine learning (Spring 2021)wesley chun
 
Exploring Google APIs with Python
Exploring Google APIs with PythonExploring Google APIs with Python
Exploring Google APIs with Pythonwesley chun
 
Serverless Computing with Google Cloud
Serverless Computing with Google CloudServerless Computing with Google Cloud
Serverless Computing with Google Cloudwesley chun
 
Run your code serverlessly on Google's open cloud
Run your code serverlessly on Google's open cloudRun your code serverlessly on Google's open cloud
Run your code serverlessly on Google's open cloudwesley chun
 
Serverless Computing with Python
Serverless Computing with PythonServerless Computing with Python
Serverless Computing with Pythonwesley chun
 

Mais de wesley chun (20)

Easy path to machine learning (2023-2024)
Easy path to machine learning (2023-2024)Easy path to machine learning (2023-2024)
Easy path to machine learning (2023-2024)
 
Powerful Google developer tools for immediate impact! (2023-24 B)
Powerful Google developer tools for immediate impact! (2023-24 B)Powerful Google developer tools for immediate impact! (2023-24 B)
Powerful Google developer tools for immediate impact! (2023-24 B)
 
Exploring Google APIs with Python
Exploring Google APIs with PythonExploring Google APIs with Python
Exploring Google APIs with Python
 
Serverless computing with Google Cloud (2023-24)
Serverless computing with Google Cloud (2023-24)Serverless computing with Google Cloud (2023-24)
Serverless computing with Google Cloud (2023-24)
 
Powerful Google developer tools for immediate impact! (2023-24 A)
Powerful Google developer tools for immediate impact! (2023-24 A)Powerful Google developer tools for immediate impact! (2023-24 A)
Powerful Google developer tools for immediate impact! (2023-24 A)
 
Build an AI/ML-driven image archive processing workflow: Image archive, analy...
Build an AI/ML-driven image archive processing workflow: Image archive, analy...Build an AI/ML-driven image archive processing workflow: Image archive, analy...
Build an AI/ML-driven image archive processing workflow: Image archive, analy...
 
Exploring Google APIs 102: Cloud vs. non-GCP Google APIs
Exploring Google APIs 102: Cloud vs. non-GCP Google APIsExploring Google APIs 102: Cloud vs. non-GCP Google APIs
Exploring Google APIs 102: Cloud vs. non-GCP Google APIs
 
Serverless Computing with Python
Serverless Computing with PythonServerless Computing with Python
Serverless Computing with Python
 
Easy path to machine learning (2022)
Easy path to machine learning (2022)Easy path to machine learning (2022)
Easy path to machine learning (2022)
 
Google... more than just a cloud
Google... more than just a cloudGoogle... more than just a cloud
Google... more than just a cloud
 
Accessing Google Cloud APIs
Accessing Google Cloud APIsAccessing Google Cloud APIs
Accessing Google Cloud APIs
 
Serverless computing with Google Cloud
Serverless computing with Google CloudServerless computing with Google Cloud
Serverless computing with Google Cloud
 
Serverless Computing with Google Cloud
Serverless Computing with Google CloudServerless Computing with Google Cloud
Serverless Computing with Google Cloud
 
Designing flexible apps deployable to App Engine, Cloud Functions, or Cloud Run
Designing flexible apps deployable to App Engine, Cloud Functions, or Cloud RunDesigning flexible apps deployable to App Engine, Cloud Functions, or Cloud Run
Designing flexible apps deployable to App Engine, Cloud Functions, or Cloud Run
 
Image archive, analysis & report generation with Google Cloud
Image archive, analysis & report generation with Google CloudImage archive, analysis & report generation with Google Cloud
Image archive, analysis & report generation with Google Cloud
 
Easy path to machine learning (Spring 2021)
Easy path to machine learning (Spring 2021)Easy path to machine learning (Spring 2021)
Easy path to machine learning (Spring 2021)
 
Exploring Google APIs with Python
Exploring Google APIs with PythonExploring Google APIs with Python
Exploring Google APIs with Python
 
Serverless Computing with Google Cloud
Serverless Computing with Google CloudServerless Computing with Google Cloud
Serverless Computing with Google Cloud
 
Run your code serverlessly on Google's open cloud
Run your code serverlessly on Google's open cloudRun your code serverlessly on Google's open cloud
Run your code serverlessly on Google's open cloud
 
Serverless Computing with Python
Serverless Computing with PythonServerless Computing with Python
Serverless Computing with Python
 

Último

AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 

Último (20)

AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 

What is Python? (Silicon Valley CodeCamp 2015)

  • 1. 1 (c) 1998-2015 CyberWeb Consulting. All rights reserved. What is Python? An Introduction "Perl is worse than Python because people wanted it worse." - Larry Wall (14 Oct 1998 15:46:10 -0700, Perl Users mailing list) "Life is better without braces." and "Python fits your brain." - Bruce Eckel, author of Thinking in C++ , Thinking in Java "Python is an excellent language [and makes] sensible compromises." - Peter Norvig (Google), author of Artificial Intelligence +Wesley Chun, Principal CyberWeb Consulting cyberwebconsulting.com (c) 1998-2015 CyberWeb Consulting. All rights reserved. Python is Fun! (I've used it at lots of places!)
  • 2. 2 (c) 1998-2015 CyberWeb Consulting. All rights reserved. (c) 1998-2015 CyberWeb Consulting. All rights reserved. I'm here to give you an idea of what it is! (I've written a lot about it!)
  • 3. 3 (c) 1998-2015 CyberWeb Consulting. All rights reserved. (c) 1998-2015 CyberWeb Consulting. All rights reserved. I've taught it at lots of places! (companies, schools, etc.)
  • 4. 4 (c) 1998-2015 CyberWeb Consulting. All rights reserved. (c) 1998-2015 CyberWeb Consulting. All rights reserved. About You SW/HW Engineer/Lead Sys Admin/IS/IT/Ops Web/Flash Developer QA/Testing/Automation Scientist/Mathematician Toolsmith, Hobbyist Release Engineer/SCM Artist/Designer/UE/UI/UX Student/Teacher Familiar with… Java, C, C++, C# PHP, JavaScript (Visual) Basic Perl, Tcl, Ruby any other high- level language… Django, Pyramid, web2py, Flask, Fabric, Plone, Trac, Mailman, App Engine
  • 5. 5 (c) 1998-2015 CyberWeb Consulting. All rights reserved. Why are you here? You… Have heard good word-of-mouth Came via Django, App Engine, Plone, etc. Discovered Google, Yahoo!, et al. use it Already know but want formal training Were forced by your boss Safari Books Online: Top 5, Apr 2009 1. iPhone 2. Java 3. Python 4. C# 5. PHP (c) 1998-2015 CyberWeb Consulting. All rights reserved. source: TIOBE Programming Community Index for April 2009 (tiobe.com)
  • 6. 6 (c) 1998-2015 CyberWeb Consulting. All rights reserved. For New Programmers Programming should be easy enough to teach like reading & writing (CP4E) What you need to be good Some math background Algebra, physics (problem solving) Buddy who already is a developer Even better if they know Python Tinkerer, curious, itch-scratcher (c) 1998-2015 CyberWeb Consulting. All rights reserved. About this Talk Goal: Introduce as much Python as one can in an hour Seminar Topics Language Introduction Python Object Types Loops and Conditionals Files, Functions, Modules Object-Oriented Programming Errors and Exception Handling Miscellaneous
  • 7. 7 (c) 1998-2015 CyberWeb Consulting. All rights reserved. Background Guido van Rossum: began late '89, released early '91 Inherits from ABC, Modula, C/C++, LISP, ALGOL, Perl, Java, etc. Named after Monty Python, not the snake Cross-platform (Mac, PC, *ix; only need a C compiler) Alternate implementations: Jython, IronPython, Stackless, PyPy, etc. Philosophy, Concepts and Syntax Robust Enough "batteries included" to get job done Simple Clean, easy-to-read, easier than VB?!? Modular Plug-n-play, use only what you need Extensible Can extend language to meet your needs Intuitive "Python fits your brain." OOP Object-oriented when you need it (not req'd) "Pythonic" "There's only one way to do it…." (c) 1998-2015 CyberWeb Consulting. All rights reserved. Disadvantages? Generally slower than compiled languages Obscure syntax? Naaah! Typing requires discipline Some idiosyncrasies and required idioms May not have your feature Memory management No marketing force… mostly word-of-mouth No world domination… yet! Why (not) Python? Advantages Simple syntax Rapid development High-level data structures Object-oriented Exception handling Functional programming Memory management Extensible (C/C++/Java) Many libraries: NW, DB, GUI, MT, XML/JSON/CSV, RE, OS/FS, Math, Web; plus 3rd-party Community www.tiobe.com/index.php/ content/paperinfo/tpci
  • 8. 8 (c) 1998-2015 CyberWeb Consulting. All rights reserved. Built for Non-Programmers Educational language syntax Scratch (Tynker, Blockly, App Inventor) , Alice, Python, HTML Works well for school-aged children Syntax, memory mgmt, data structures, OOP… Obstacles to learning concepts, deters interest Python: retention, morale, understanding Probably the "best" 1st language What about professional developers? C/C++, Java, PHP, Python, Ruby, JavaScript (c) 1998-2015 CyberWeb Consulting. All rights reserved. Some Newbie Resources Published Books Hello World! Computer Programming for Kids & Other Beginners (Sande, Sande: 2013) Invent Your Own Computer Games with Python (Sweigart: 2015) Python for Kids (Briggs: 2012; see Snake Wrangling for Kids) Automate the Boring Stuff with Python: Practical Programming for Total Beginners (Sweigart: 2015) Learning with Python: How to Think Like a Computer Scientist (Downey, Elkner, Meyers: 2002) Online Books, Tutorials, Environments, etc. How to Think Like a Computer Scientist (Downey, Elkner, Meyers) Learning to Program (Gauld) LiveWires Python course A Byte of Python (Swaroop) Instant Hacking: Learning to Program with Python (Hetland) Snake Wrangling for Kids (Briggs) Computer Programming is Fun! (Handy) Karel the Robot clones: Guido van Robot, RUR-PLE
  • 9. 9 (c) 1998-2015 CyberWeb Consulting. All rights reserved. Run Python interactive interpreter from default IDE: IDLE Or do it from the cmd-line or DOS command shell $ python # or C:> python Python 2.7.10 (default, Jul 27 2015, 11:35:10) [GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> >>> print 'Hello World!' Hello World! Interactive Interpreter To exit: Ctrl-D in IDLE or *ix cmd line; or Ctrl-Z in DOS (c) 1998-2015 CyberWeb Consulting. All rights reserved. What You Just Saw >>> this is the Python prompt Enter any Python command after it Use print to display output to users Use print() in Python 3 To exit interactive interpreter Ctrl-D from IDLE or *ix command-line Ctrl-Z from a DOS/command shell Interactive Interpreter: testing, debugging, hacking, experimenting regardless of IDE use or otherwise
  • 10. 10 (c) 1998-2015 CyberWeb Consulting. All rights reserved. Getting Python POSIX (Mac OS, *nix): already installed PC, source, and other downloads python.org or corepython.com Other IDEs SPE (pictured) PythonWin Eclipse & PyDev PyCharm/intelliJ Komodo WingIDE IPython Notebook (c) 1998-2015 CyberWeb Consulting. All rights reserved. Online Python interpreters/shells • Can't or don't wish to install Python locally? • Run Python from just a web browser •ideone.com •colabv6.dan.co.jp/lleval.html •doc.pyschools.com/console •repl.it/languages/Python •skulpt.org (pure JS implementation; allows turtle) •pythonwebconsole.thomnichols.org •shell.appspot.com (Google App Engine + libraries) •codepad.org •lotrepls.appspot.com •datamech.com/devan/trypython/trypython.py • Most are 2.x, some (top pair) do 3.x • Some support multiple languages
  • 11. 11 (c) 1998-2015 CyberWeb Consulting. All rights reserved. Online learning systems •Learn & code Python with these learning environments •Codecademy •codecademy.com/tracks/python •PySchools •pyschools.com •Online Python Tutor •pythontutor.com •Online Python course •Udacity •udacity.com/course/cs101 •Coursera •coursera.org/course/interactivepython •coursera.org/course/programming1 •LearnPython.org •learnpython.org •CodingBat (login optional) •codingbat.com/python •SingPath (login required) •singpath.com (c) 1998-2015 CyberWeb Consulting. All rights reserved. Hello World! Using print statement or function print 'Hello World!' # 2.x print('Hello World!') # 3.x Or for 3.x compatibility & "futureproofing:" from __future__ import print_function # works in both 2.x and 3.x print('Hello World!')
  • 12. 12 (c) 1998-2015 CyberWeb Consulting. All rights reserved. Common Beginner Gotchas Code delimited by indentation not braces { } if x > 10: return "'x' is greater than 10" else: return "'x' is less than 10" No extraneous characters ( ; , $, ……) No switch-case, private class members, ++/--, static type checking, anonymous blocks, etc. Freaky-looking floats*: 1.1 1.10000000001 Single element tuple needs comma: (None,) 3.x-only: print() & true div: 1/2 == 0.5 (c) 1998-2015 CyberWeb Consulting. All rights reserved. Variables and Expressions >>> 4 + 6 * 5 # math ops like other langs 34 >>> a = 4 + 6 ** 2 # no declaration needed >>> a 40 >>> a = 'Python' # auto garbage collection >>> b = 'is cool' >>> a + b # ops can be overloaded 'Pythonis cool' >>> a = a + ' ' + b # reassignment no problem >>> a 'Python is cool' >>> # useful interactive tool
  • 13. 13 (c) 1998-2015 CyberWeb Consulting. All rights reserved. Objects Standard Data Types Numbers (3-8) Strings (2-3) Lists Tuples Dictionaries Sets (2) Other Types None Files, Modules Functions/Methods Iterators/Generators Type/Classes miscellaneous Allocated on assignment: Dynamic/Duck Typing Memory Management: Reference Counting Variables not declared: type inferred on assignment (c) 1998-2015 CyberWeb Consulting. All rights reserved. Standard Operators + - * / // % ** << >> & | ^ ~ == >= <= < > != is is not and or not •Grouping expressions in ( ) okay as usual •** means exponentiation, % means modulus/remainder •/ means true division in 3.x and classic division in 2.x •Use // for standard integer floor division •Assignment using single equals ( = ) •Augmented assignment +=, -=, *=, etc. (no ++ though)
  • 14. 14 (c) 1998-2015 CyberWeb Consulting. All rights reserved. Numbers integers (no size limit except for VM) -680, 0o237, 0xDEADBEEF, 64-0x41, 0b110 floating point real numbers (IEEE-754 C double) -97.65, -3.14159, -6e2, 0.1 complex numbers Composed of real and imaginary parts (floats) 11.65-5.55J, 4J, -3e2+8.73J, 0.1-2.3e4J Also long, bool, Decimal, Fraction, Rational, etc. Other modules: math, cmath, random, operator (c) 1998-2015 CyberWeb Consulting. All rights reserved. Strings ' ' " " ''' ''' Strings are sequences of characters (single/double quotes) No 'char' type… strings of length 1 Format operator ( % ) for printf()-like functionality Flexible alternative: string format() method (new in 2.6) Triple quotes allow special characters like newlines >>> x = 'Python' >>> x * 2 'PythonPython' >>> x *= 2 >>> x 'PythonPython' >>> x[-1] 'n' >>> x[-4:-1] 'tho' >>> 'ton' in x False >>> '%s is number %d' % (x[:6], 1) 'Python is number 1' >>> '{0} is #{1}'.format(x[:6], 1) 'Python is #1' >>> >>> hi = '''hi there''' >>> hi 'hinthere' >>> print(hi) hi there
  • 15. 15 (c) 1998-2015 CyberWeb Consulting. All rights reserved. Lists [ ] and Tuples ( ) Lists: ordered sequences of arbitrary objects Mutable (values can be updated) Can have lists of lists, i.e., multidimensional indexing Tuples similar but immutable (no value updates allowed) "List comprehensions" allows for quick logical building of lists Common list methods: list.sort() # "sort" list contents in-place list.reverse() # reverse a list in-place list.append() # append item to list list.insert() # insert items in list list.remove/pop() # remove item(s) from list list.extend() # extend a list with another one list.count() # return number of item occurrences list.index() # lowest index where item is found (c) 1998-2015 CyberWeb Consulting. All rights reserved. List Operations >>> m = ['Core', 'Programming', 9, 2006] >>> m.append('Prentice Hall') >>> m.insert(1, 'Pytho') >>> m ['Core', 'Pytho', 'Programming', 9, 2006, 'Prentice Hall'] >>> m[1] = 'Python' >>> m.pop(3) 9 >>> m ['Core', 'Python', 'Programming', 2006, 'Prentice Hall'] >>> m.sort() >>> m [2006, 'Core', 'Prentice Hall', 'Programming', 'Python'] >>> [i*3 for i in range(20) if i % 2 == 0] [0, 6, 12, 18, 24, 30, 36, 42, 48, 54] >>> f = open('myFile', 'r') >>> data = [line.strip() for line in f] >>> f.close()
  • 16. 16 (c) 1998-2015 CyberWeb Consulting. All rights reserved. Dictionaries { } Dictionaries (sets like dicts but only hashed keys) Mutable, resizable hash tables Mappings of keys to values Keys: scalar (usually strings or numbers) Values: arbitrary Python objects No key collisions allowed Similar to Java HashMap, JS Object, Perl hash/associative array Most commonly-used methods: d.items() # iterable: key-value pairs d.get() # return key's value (or default) d.setdefault() # return key's value, set if nec. d.pop() # remove item from d and return d.update() # merge contents from another dict (c) 1998-2015 CyberWeb Consulting. All rights reserved. Dictionary Operations >>> d = {'title': 'Core Python Programming', 'year': 2006} >>> d {'year': 2006, 'title': 'Core Python Programming'} >>> 'year' in d True >>> 'pub' in d False >>> d.get('pub', 'N/A') # KeyError if d['pub'] 'N/A' >>> d['pub'] = 'Prentice Hall' >>> d.get('pub', 'N/A') # no KeyError for d['pub'] now 'Prentice Hall' >>> for eachKey in d: print(eachKey, ':', d[eachKey]) year : 2006 pub : Prentice Hall title : Core Python Programming
  • 17. 17 (c) 1998-2015 CyberWeb Consulting. All rights reserved. if-elif-else Statements Conditional statements are what you expect # prompt, get, and check user input data = raw_input("Enter 'y' or 'n': ") if data[0] == 'y': print("You typed 'y'.") # 'y' key elif data[0] == 'n': print("You typed 'n'.") # 'n' key else: print('invalid key!') # other key Ternary Operator (aka Conditional Expressions: C ? T : F) smaller = x if x < y else y # T if C else F (c) 1998-2015 CyberWeb Consulting. All rights reserved. Loops Python while loops are same as in other languages for more like shell foreach & used ~90% over while Iterate over elements rather than counting/conditional range() helps "simulate" traditional for loops Loop "friends" break & continue also here aList = [123, 'xyz', 45.67] >>> for eachItem in aList: ... print(eachItem) 123 xyz 45.67 >>> for i in range(0, 3, 1): # think "for (i=0; i<3; i+=1)" ... print(i) 0 1 2 >>> i = 0 >>> while i < 3: ... print(i) ... i += 1 0 1 2
  • 18. 18 (c) 1998-2015 CyberWeb Consulting. All rights reserved. Open a file and get back a file object f = open(name, mode) # mode: r/r+, w, a, U Most commonly-used file methods f.close() Close file f.read() Read bytes from file f.write() Write a string to file Display text file example: f = open('data.txt', 'r') for line in f: print(line.rstrip()) f.close() … or, alternatively, more modern Python (2.6+) with open('data.txt', 'r') as f: for line in f: print(line, end='') Files (c) 1998-2015 CyberWeb Consulting. All rights reserved. Function declaration syntax and example def func_name([v1,…, vN=dv,… *args, **kwargs): "documentation string" function_body def addYor10(x, y=10): # 'y' has default value "adds 'x' and 'y'; latter defaults to 10" return x + y Functions heterogenous (untyped) Default values & variable arguments supported Can return 0, 1, or more objects Python returns None if no return value provided Introducing Functions
  • 19. 19 (c) 1998-2015 CyberWeb Consulting. All rights reserved. Importing Modules & Attributes Importing modules or packages using import statement import module_name import string num = string.atoi('123') Importing module attributes using from-import statement Names brought into (global) variable namespace from module_name import module_element from string import atoi num = atoi('123') Packages: allow for organizing modules using the file system Use int()though… (c) 1998-2015 CyberWeb Consulting. All rights reserved. Standard Library Sampler (“B.I.”) API for SQLite databasessqlite3 Email processingemail, {smtp,pop,imap}lib External process managementsubprocess Data compression and archive filesgzip, bz2, zipfile, tarfile Various Internet client libraries{ftp,url,http,*}lib Serialize Python objectspickle, cPickle, shelve Various math/numberic processing{c,}math, random, fractions,…… High-level threads/multiprocess APIsthreading, multiprocessing Python/Tk GUI toolkit interfaceTkinter Socket interface & server classes (TCP, UDP)socket, SocketServer Date and time constants and functionstime, datetime, calendar Text processingre, csv, json, xml Operating and file system interfaceos and os.path System data, processing, and functionalitysys DescriptionModule Name(s)
  • 20. 20 (c) 1998-2015 CyberWeb Consulting. All rights reserved. Programmer Tools Debugger pdb Profilers profile hotshot cProfile Tracer/Tracker trace Logger logging Timer timeit Help/Documentation pydoc Testing unittest doctest (external) nose (external) py.test Testing tools taxonomy goo.gl/Fpz0Z (c) 1998-2015 CyberWeb Consulting. All rights reserved. Object-Oriented Programming "Constructor"/Initializer is __init__(), "self" is "this" Class instantiation via function interface (rather than "new") Instance attrs, multiple inheritance; no overloading nor private class MyClass(object): ... def __init__(self, data=2): ... self.info = data ... def times(self, x): ... return "%d * %d is %d" % ( ... self.info, x, self.info * x) >>> >>> inst = MyClass(21) >>> inst.info 21 >>> print inst.times(3) 21 * 3 is 63
  • 21. 21 (c) 1998-2015 CyberWeb Consulting. All rights reserved. Exceptions and try-except Exception handling via try-except statement try: # statements to monitor except ExceptionName as e: # code to exec if ExceptionName occurs try: f = open('data.txt', 'r') except IOError as e: print("Can't open file:", e) return False # or sys.exit(1), etc. Throw exceptions with raise; there is also a finally (c) 1998-2015 CyberWeb Consulting. All rights reserved. Python 2 vs. Python 3 The What and the Why Fix early design flaws Some new features, many small improvements Plan: develop (remainder of) 2.x and 3.x together Provide transition tools (2to3, 2.6+, -Q, -3) Key Updates (no major syntax changes) print, exec changed to functions True division: 1/2 == 0.5 Performance (more iterators, fewer lists) Consolidation/unification (integers, classes) Strings: Unicode default; bytes/bytearray types Intro to Python 3 article FYI informit.com/articles/article.aspx?p=1328795
  • 22. 22 (c) 1998-2015 CyberWeb Consulting. All rights reserved. Where do you go from here? •The tip of the iceberg… System Administration scripting tools and automation Networked/Internet Client-Server systems Graphical User Interface (GUI) design and development Web frameworks and rich Internet applications (RIA) Scientific/numeric/mathematics-centric development Database programming, Object-Relational Mappers (ORMs) XML, JSON, CSV and other forms of text processing Java with Jython; .NET/Mono with IronPython; COM, MFC Graphics/imaging/multimedia/visual art processing Multithreaded and higher-performance applications Embedded system design (hardware as well as Python) QA/Testing automated test tools, suites, and frameworks Rapid application prototyping (all application areas) (c) 1998-2015 CyberWeb Consulting. All rights reserved. Additional Resources Books for programmers (more @ goo.gl/i4u0R) Quick Python Book (2010) Python Fundamentals LiveLessons DVD (Chun, 2009) Core Python Programming (2006 [2009]) Dive into Python (2009, 2004) Beginning Python: From Novice to Professional (2008) Python Cookbook (2013, 2005) Python Standard Library by Example (2011) Python Essential Reference (2009) & Python in a Nutshell (2006) Some online resources Python Quick Reference Guide rgruet.free.fr#QuickRef Python Conferences worldwide www.pycon.org Core Python Programming corepython.com Mailing list/newsgroup groups.google.com/group/comp.lang.python Python Docs (+ FAQ, tutorial,…) docs.python.org External 3rd-party/ repo python.org/pypi
  • 23. 23 (c) 1998-2015 CyberWeb Consulting. All rights reserved. 1. Beautiful is better than ugly. 2. Explicit is better than implicit. 3. Simple is better than complex. 4. Complex is better than complicated. 5. Flat is better than nested. 6. Sparse is better than dense. 7. Readability counts. 8. Special cases aren't special enough to break the rules. 9. Although practicality beats purity. 10. Errors should never pass silently. 11. Unless explicitly silenced. 12. In the face of ambiguity, refuse the temptation to guess. 13. There should be one — and preferably only one — obvious way to do it. 14. Although that way may not be obvious at first unless you're Dutch. 15. Now is better than never. 16. Although never is often better than right now. 17. If the implementation is hard to explain, it's a bad idea. 18. If the implementation is easy to explain, it may be a good idea. 19. Namespaces are one honking great idea — let's do more of those! The Zen of Python (or import this by Tim Peters) (c) 1998-2015 CyberWeb Consulting. All rights reserved. Thank you! Questions? +Wesley Chun # Google+ @wescpy # Twitter wescpy@gmail.com # e-mail corepython.com # books cyberwebconsulting.com # training wescpy.blogspot.com # Python blog wesc.livejournal.com # personal blog
  • 24.
  • 25. THE COMPLETE DEVELOPER'S GUIDE TO PYTHON • New to Python? The definitive guide to Python development for experienced programmers • Covers core language features thoroughly, including those found in the latest Python releases — learn more than just the syntax! • Learn advanced topics such as regular expressions, networking, multithreading, GUI, Web/CGI, and Python extensions • Includes brand-new material on databases, Internet clients, Java/Jython, and Microsoft Office, plus Python 2.6 and 3 • Presents hundreds of code snippets, interactive examples, and practical exercises to strengthen your Python skills Python is an agile, robust, expressive, fully object-oriented, extensible, and scalable programming language. It combines the power of compiled languages with the simplicity and rapid development of scripting languages. In Core Python Programming, Second Edition, leading Python developer and trainer Wesley Chun helps you learn Python quickly and comprehensively so that you can immediately succeed with any Python project. Using practical code examples, Chun introduces all the fundamentals of Python programming: syntax, objects and memory management, data types, operators, files and I/O, functions, generators, error handling and exceptions, loops, iterators, functional programming, object-oriented programming and more. After you learn the core fundamentals of Python, he shows you what you can do with your new skills, delving into advanced topics, such as regular expressions, networking programming with sockets, multithreading, GUI development, Web/CGI programming and extending Python in C. This edition reflects major enhancements in the Python 2.x series, including 2.6 and tips for migrating to 3. It contains new chapters on database and Internet client programming, plus coverage of many new topics, including new-style classes, Java and Jython, Microsoft Office (Win32 COM Client) programming, and much more. • Learn professional Python style, best practices, and good programming habits • Gain a deep understanding of Python's objects and memory model as well as its OOP features, including those found in Python's new-style classes • Build more effective Web, CGI, Internet, and network and other client/ server applications • Learn how to develop your own GUI applications using Tkinter and other toolkits available for Python • Improve the performance of your Python applications by writing extensions in C and other languages, or enhance I/O-bound applications by using multithreading • Learn about Python's database API and how to use a variety of database systems with Python, including MySQL, Postgres, and SQLite • Features appendices on Python 2.6 & 3, including tips on migrating to the next generation! Core Python Programming Second Edition "The long-awaited second edition of Wesley Chun's Core Python Programming proves to be well worth the wait–its deep and broad coverage and useful exercises will help readers learn and practice good Python." — ALEX MARTELLI, author of Python in a Nutshell and editor of Python Cookbook "There has been lot of good buzz around Wesley Chun's Core Python Programming. It turns out that all the buzz is well earned. I think this is the best book currently available for learning Python. I would recommend Chun's book over Learning Python (O'Reilly), Programming Python (O'Reilly), or The Quick Python Book (Manning)." — DAVID MERTZ, Ph.D., IBM DeveloperWorks® "Finally, a book good enough to be both a textbook and a reference on the Python language now exists." — MICHAEL BAXTER, Linux Journal Wesley Chun FOR MORE INFORMATION PLEASE VISIT: informit.com/python Available wherever technical books are sold. AVAILABLE • BOOK: 9780132269933 • SAFARI ONLINE • E-BOOK: 9780137060566 • SONY: 9780137061259 SAVE up to 40% Buy 1 Save 35% | Buy 2 or More and Save 40% Use discount code: PYTHONCENTER at informit.com/python
  • 26. Other titles by Wesley Chun FOR MORE INFORMATION PLEASE VISIT: informit.com/python Available wherever technical books are sold. SAVE up to 40% Buy 1 Save 35% | Buy 2 or More and Save 40% Use discount code: PYTHONCENTER at informit.com/python About the Author WESLEY J. CHUN, MSCS, is the author of Python Fundamentals, a companion video to Core Python Programming, and the coauthor of Python Web Development with Django. In addition to being a senior software architect, he runs CyberWeb (cyberwebconsulting.com), a consulting business specializing in Python software engineering and technical training. He has more than twenty-five years of programming, teaching, and writing experience, including more than a decade with Python. While at Yahoo!, he helped create Yahoo!Mail and Yahoo! People Search using Python. He holds degrees in computer science, mathematics, and music from the University of California. Python Web Development with Django JEFF FORCIER, PAUL BISSEX, WESLEY CHUN | ISBN: 9780132356138 Using the simple, robust, Python-based Django framework, you can build powerful Web solutions with remarkably few lines of code. In Python Web Development with Django®, three experienced Django and Python developers cover all the techniques, tools, and concepts you need to make the most of Django 1.0, including all the major features of the new release. The authors teach Django through in-depth explanations, plus provide extensive sample code supported with images and line-by-line explanations. You’ll discover how Django leverages Python’s development speed and flexibility to help you solve a wide spectrum of Web development problems and learn Django best practices covered nowhere else. You’ll build your first Django application in just minutes and deepen your real-world skills through start-to-finish application projects. Python Fundamentals (Video Training) WESLEY CHUN | ISBN: 9780137143412 FOR ANY STUDENT OR PROFESSIONAL INTERESTED IN LEARNING THE FUNDAMENTALS OF PYTHON In this one-of-a-kind video package, leading Python developer and trainer Wesley Chun helps you learn Python quickly and comprehensively, so that you can immediately succeed with any Python project. Just click and watch: One step at a time, you will master Python fundamentals. If you already have Python experience, these videos will help further develop your skills. The lessons start with an introduction to the core features of the Python language, including syntax basics and standard types and operations. The lessons progress into advanced topics, such as Python’s memory model and object-oriented programming.