Show Menu
Cheatography

Python Basics Cheat Sheet (DRAFT) by

Basic Python Sheet

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Variable Types

10
Int
10.0
Float
1 + 2j
Complex
'a'
or
"­a"
String
(1, 2, 3)
Tuple
['a', 'b', 'c']
List
{'azul': 'blue', 'rosa': 'pink'}
Dictionary
{1, 4, 5}
Set
True
/
False
Boolean
None
NoneType
print()
Fuction

Math - Operations

a = 2
Assign 2 to a
b = 3
Assign 3 to b
a + b
a plus b (5)
a - b
a minus b (-1)
a * b
a times b (6)
a / b
a divided by b (0.666­6666)
a // b
Floor division of a by b (0)
a % b
Remainder of a divided by b (2)
a ** b
a to the power of b (8)

Math - Functions

import math
Imports the math module
math.c­eil(x)
Rounds x up
math.f­loor(x)
Rounds x down
round(x)
1
Rounds x up or down
math.s­qrt(x)
Square root of the x
math.s­in(­angle)
Sine of angle
math.c­os(­angle)
Cosine of angle
math.t­an(­angle)
Tangent of angle
math.a­sin­(angle)
Arcsine of angle
math.a­cos­(angle)
Arccosine of angle
math.a­tan­(angle)
Arctangent of angle
math.s­inh­(angle)
Hiperbolic sine of angle
math.c­osh­(angle)
Hiperbolic cosine of angle
math.d­egr­ees­(angle)
Convert angle from radians to degrees
math.r­adi­ans­(angle)
Convert angle from degrees to radians
math.e­xp(x)
e to the power of x
math.l­og(x)
Natural logarithm of x
math.l­og(x, 2)
Base 2 logarithm of x
math.f­act­ori­al(x)
Factorial of x
math.g­amma(x)
Gamma function of x
math.e
e constant
math.pi
pi constant
1
round
is not part of the
math
module
 

Basic Functions

print(­"­str­ing­")
Prints string to the screen
input(­"­str­ing­")
Prints a string and waits takes keyboard input
len(my­_tuple)
Returns the number of elements of a sequence
type(v­ari­able)
Returns the type of the variable