python tutorial.ppt

Reviews
Shared by: techmaster
Stats
views:
141
rating:
not rated
reviews:
0
posted:
10/28/2008
language:
English
pages:
0
A Caffeinated Crash Course in Python Python is not…. • Java • C • Perl The Python Interpreter • Type “python” at the command prompt • In windows, find the python icon on the start menu Dir and Help help() dir() Syntax Errors • Python Errors show the line number of the error • Check the line above if your error makes no sense White Space String Basics • Not a mutable data type • String can be delimited with either the “ or ‘ More Strings • Concatenation uses the + • You can do math with strings! Output Indexing • To index into a string, specify the position inside square brackets • You can index into a string from the “end” of the string. Slicing • A Substring of a string is a slice • Your head or tail can be a negative index More Slicing • You don’t need to specify the beginning and end of the string • Find the length of a string with len() Example Lists • Lists in python are made of any data type delimited by commas and surrounded by brackets. • Lists are mutable More on Lists • You can index into lists • You can slice lists Modifying Lists • You can add lists • And append to them List Methods • sort - sorts the list in place, returns nothing • sorted - does not modify the list, returns new sorted list • reverse - reverses the list in place, returns nothing String Formatting • The % operator substitutes values into a string • %s and %d are placeholders for the values (%d makes sure it’s a number) • “%s has %d letters” % (“colorless”, len(“colorless”)) becomes the string “colorless has 9 letters” Converting from Strings to Lists • Join a list to make a string • Split a string to make a list For and If • If statements • For Statements List Comprehensions • Applies a function to every element of a list Dictionaries • Hash - maps things to things! Even More Dictionaries Example: Letter Frequencies Classes Importing and the Python path • Import using the import command • You can import everything from a module using the syntax “from import *” Files Filename = “/home/havasi/input.txt” input = open(Filename, ‘r’) output = open(Filename + ‘.out’, ‘w’) for line in input.readlines(): input.write(‘Cows! \n’) input.close() output.close() Resources • Python.org • NLTK Python Tutorial – http://nltk.org/doc/en/programming.html • IDLE (Windows Development Env.) – http://www.python.org/idle/

Related docs
titus pycon07 tutorial.ppt
Views: 16  |  Downloads: 0
PYTHON
Views: 8  |  Downloads: 0
Python
Views: 3  |  Downloads: 0
Python
Views: 133  |  Downloads: 8
Python-with-COM
Views: 3  |  Downloads: 3
Python Tutorial
Views: 91  |  Downloads: 4
Python Tutorial
Views: 214  |  Downloads: 23
Introduction to Python
Views: 69  |  Downloads: 15
Python Tutorial
Views: 483  |  Downloads: 13
Python Tutorial
Views: 90  |  Downloads: 16
Name Burmese Python
Views: 0  |  Downloads: 0
Python Power
Views: 46  |  Downloads: 13
A Byte of Python
Views: 2  |  Downloads: 0
Introduction to Python III
Views: 59  |  Downloads: 14
Other docs by techmaster
tr115
Views: 47  |  Downloads: 0
ANGEL FINANCING FOR ENTREPRENEURS[2]
Views: 110  |  Downloads: 2
Legislation urges investing in early-stage
Views: 67  |  Downloads: 0
Moore's law and wireless gaming
Views: 189  |  Downloads: 6
nc130
Views: 42  |  Downloads: 0
OTCBB can be used as a stepping stone to listing
Views: 198  |  Downloads: 7
Contract OUTLINE[1]
Views: 314  |  Downloads: 5
ud105
Views: 162  |  Downloads: 1
nc110_001
Views: 36  |  Downloads: 0
Fund Raising Sales Agreement
Views: 646  |  Downloads: 9
nc300_001
Views: 46  |  Downloads: 0
pos040p_001
Views: 47  |  Downloads: 0
mc958
Views: 66  |  Downloads: 0
Reverse Merger Info
Views: 1146  |  Downloads: 48
tr106
Views: 68  |  Downloads: 0