What is Python? I Object-oriented, rapid prototyping language I Multi-purpose: Web, GUI, scripting, science, etc. I Interpreted and interactive; very easy to learn I Strongly typed and dynamically typed I Focus on readability and productivity I Extensive standard library and community I CPython, Jython, IronPython, PyPy, etc. I Home page: http://www.python.org/ Python 101 1 Who uses Python? I Google (various projects) I NASA (several projects) I NYSE (one of only three languages \on the floor") I Industrial Light & Magic (everything) I Yahoo! (Yahoo mail & groups) I RealNetworks (function and load testing) I RedHat and Ubuntu (Linux installation tools) I LLNL, Fermilab (steering scientific applications) More success stories at http://www.pythonology.com/ Python 101 2 Python vs Java Python Java I Dynamically typed I Statically typed (assign names to values) (must declare variables) I Concise: \expressing much I Verbose: \abounding in in a few words; implies words; using or containing clean-cut brevity, attained by more words than are excision of the superfluous” necessary" import java.io.*; ... # open the filed.txt // open the filed.txt myFile = open("d.txt") BufferedReader myFile = new BufferedReader( new FileReader("d.txt")); http://pythonconquerstheuniverse.wordpress.com/category/java-and-python/ Python 101 3 Some Basics I Indentation matters (no braces!) I Type matters (must be consistent) I Comments start with a # I Strings use 's or "s (or """s) I print (vs System.out.println) I None ≈ null, self ≈ this I and, or, not instead of &&, jj,! I [1, 2, 3] is a list (≈ ArrayList) Python 101 4 Discete Math Example """Simple demo of the Caesar Cipher.""" def encrypt(msg, k): """Shifts msg byk letters, ignoring spaces.""" ans ="" forc in msg: if'a' <= c <='z': p = ord(c) - ord('a')# char to int q = (p + k) % 26 c = chr(q + ord('a'))# int to char ans += c return ans if __name__ =="__main__": print encrypt("hello world", 3) Python 101 5 Editors & Tools Recommended: your favorite editor I Linux: http://www.geany.org/ I Windows: http://notepad-plus-plus.org/ I Mac: http://www.barebones.com/products/textwrangler/ Optional: heavyweight IDE I Eclipse + PyDev: http://pydev.org/ Command Line I IPython http://ipython.org/ I Mac/Windows: requires readline module I PyChecker http://pychecker.sourceforge.net/ Python 101 6 Ready, Set, Learn! Official Documentation I Tutorial: http://docs.python.org/2/tutorial/ I Reference: http://docs.python.org/2/reference/ I Modules: http://docs.python.org/2/py-modindex.html Free Textbooks I Dive Into Python http://diveintopython.org/ I How to Think Like a Computer Scientist http://www.greenteapress.com/ Online Tutorials I http://www.codecademy.com/tracks/python I http://www.learnpython.org/ Python 101 7.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages7 Page
-
File Size-