Python_quickref - Python Quick Reference Card Loosely...

Info icon This 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
Image of page 1

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern