Show Menu
Cheatography

Python Cheat Sheet (DRAFT) by

Python Cheat Sheet - Level Basic

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

Commets

#This is a comment
" " "
This is a comment written
in more than
just one line
" " "

Variables

x = 5
5 John
y = "­Joh­n"
print(x, y)

Data Types

str
x = "­Hello World"
int
x = 20
float
x = 20.5
 

Strings

a = "­Hello, World!­"
e
print(­a[1])
!! H = 0 position
for x in "­ban­ana­":
b
print(x)
a
 
n
 
a
 
n
 
a
a = "­Hello, World!­"
13
print(­len(a))
space is included in the len
txt = "The best things in life are free!"
print(­"­fre­e" in txt)
True
print(­"­fre­e" not in txt)
False
b = "­Hello, World!­"
llo
print(­b[2:5])
 

Operators

+
x + y
-
x - y
*
x * y
/
x / y
%
3 % 2 = 1 , 7 % 2 = 1
**
3 ** 2 = 3 ^ 2
==
Equal
!=
Not equal
&
AND
|
OR