A Caffeinated Crash Course In Python - MIT

2y ago
79 Views
8 Downloads
482.27 KB
28 Pages
Last View : 22d ago
Last Download : 2m ago
Upload by : Ronan Orellana
Transcription

A Caffeinated Crash Course inPython

Python is not . Java C Perl

The Python Interpreter Type “python” at the command prompt In windows, find the python icon on thestart menu

Dir and Helphelp()dir()

Syntax Errors Python Errors show the line number ofthe error Check the line above if your error makesno 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 positioninside square brackets You can index into a string from the “end” ofthe string.

Slicing A Substring of a string is a slice Your head or tail can be a negativeindex

More Slicing You don’t need to specify the beginningand end of the string Find the length of a string with len()

Example

Lists Lists in python are made of any datatype delimited by commas andsurrounded 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 newsorted list reverse - reverses the list in place, returnsnothing

String Formatting The % operator substitutes values into astring %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 9letters”

Converting fromStrings 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 alist

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 amodule using the syntax “from module import *”

FilesFilename “/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/

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

Related Documents:

CRASH COURSE TEST PREPS: ADVANCED PLACEMENT TITLE ISBN 13 ISBN 10 PAGES PRICE AP Crash Course AP Art History Crash Course 2nd Ed. 978--7386-1200-3 -7386-1200-6 256 14.95 AP Biology Crash Course 2nd Ed. 978--7386-1099-3 -7386-1099-2 224 14.95 AP Calculus AB & BC Crash Course 2nd Ed. 978--7386-1219-5 -7386-1219-7 240 14.95

top crash-types, testers file bugs in Bugzilla and link them to the corresponding crash-type in the Socorro server. Multiple bugs can be filed for a single crash-type and multiple crash-types can be associated with the same bug. For each crash-type, the Socorro server provides a crash-type summary, i.e.,

6 Definitions of police reported casualty types: Casualty Crash - crash where at least one fatality, serious injury or minor injury occurs. Casualty - A fatality, serious injury or minor injury. Fatal Crash - A crash for which there is at least one fatality. Fatality - A person who dies within 30 days of a crash as a result of injuries sustained in that crash.

nutrients Article The Acute Effects of Caffeinated Black Coffee on Cognition and Mood in Healthy Young and Older Adults Crystal F. Haskell-Ramsay 1,* , Philippa A. Jackson 1, Joanne S. Forster 1, Fiona L. Dodd 1, Samantha L. Bowerbank 2 and David O. Kennedy 1 1 Brain, Performance and Nutrition Research Centre, Northumbria University, Newcastle Upon-Tyne NE1 8ST, .

AP Macroeconomics Crash Course 978--7386-0971-3: -7386-0971-4 304 : 14.95 AP Microeconomics Crash Course: 978--7386-0972- -7386-0972-2: 208 14.95: AP Physics 1: Crash Course 978--7386-1196-9: -7386-1196-4 240: 14.95 . AP Crash Course .

CRASH COURSE TEST PREPS: ADVANCED PLACEMENT W tly Released TITLE ISBN 13 ISBN 10 PAGES PRICE AP Crash Course AP Art History Crash Course 2nd Ed. Recently Released 978--7386-1200-3 -7386-1200-6 256 14.95 AP Biology Crash Course 2nd Ed. 978--7386-1099-3 -7386-1099-2 224 14.95

Safety Benefit-Cost Analysis Guide and Tool as well as procedures to (1) update the crash unit costs over time, and (2) adjust the crash unit costs to States based on State-specific cost of living, injury-to-crash ratios, and vehicle-to-crash ratio.

Although there are different types of reports, in general, an academic report is a piece of informative writing, an act of communication and an account of an investigation (Reid, 2012). An academic report aims to sell a product, idea or points of view (Van Emden and Easteal, 1995). It should inform, explain and persuade (Williams, 1995) by using well- organised research. Sometimes it will .