Show Menu
Cheatography

Python Cheat Sheet (DRAFT) by

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

Python Indexes and Slices

a[-1]
5
a[-2]
4
a[1:]
[1,2,3­­,4,5]
a[:5]
[0,1,2­­,3,4]
a[:-2]
[0,1,2,3]
a[1:3]
[1,2]
a[1:-1]
[1,2,3,4]
b=a[:]
Shallow copy of a
Indexes and Slices of a=[0,1­Â­,­2,­­3,4,5]
 

Useful patterns

dict.s­etd­efa­ult­(key, [])
list as value