Python_quickref - Python Quick Reference Card Loosely...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Python Quick Reference Card Loosely adopted from John Zelle’s “Python Programming: An Introduction to Computer Science”, Franklin, Beedle, 1994. Python Reserved Words and del for is raise assert elif from lambda return break else global not try class except if or while continue exec import pass yield def finally in print print Statement print <expr> print <expr>, <expr>, . .., <expr> print <expr>, <expr>, . .., <expr>, Assignment Statement <variable> = <expr> <variable1>, <variable2>, . .., <variableN> = <expr1>, <expr2>, . .., <exprN> Input (numeric) <variable> = input(<prompt>) <variable1>, <variable2>, . .., <variableN> = input(<prompt>) Input (string) <variable> = raw_input(<prompt>) Definite Loop (iteration) for <variable> in <sequence>: <body> while Loop while <condition>: <body> break Statement while True: ... if <condition>: break ... Module Import import <module_name> from <module_name> import <name1>, <name2>, . .. from <module_name> import * -1- Numeric Operators Operator Operation + addition - subtraction * multiplication / division ** exponentiation % integer remainder (modulus) abs() absolute value Math Library Functions Name Returns pi an approximation of pi e an approximation of e sin(x) sine of x radians cos(x) cosine of x radians tan(x) tangent of x radians asin(x) inverse of sine x radians acos(x) inverse of cosine x radians atan(x) inverse of tangent x radians log(x) natural log of x degrees(x) converts x radians to degrees radians(x) converts x degrees to radians log10(x) base 10 log of x exp(x) exponential of x ceil(x) smallest integer >= x floor(x) largest integer <= x sqrt(x) square root of x Common Built-in Functions Name Returns range(n) list of ints from 0 to n-1 range(m,n) list of ints from m to n-1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/28/2011 for the course CMPT 125 taught by Professor Diana during the Spring '08 term at Simon Fraser.

Page1 / 2

Python_quickref - Python Quick Reference Card Loosely...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online