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.

Max value

In Python, value of an integer is not restricted by the number of bits and can expand to the limit of the available memory

Transpose

matrix
[[m[j][i] for j in range(­len­(m))] for i in range(­len­(m[­0]))]
array
zip(*m­atrix)
array
numpy.t­ra­nsp­ose­(ma­trix))

Type Conversion

int(a,­base)
int
float()
float point
ord()
char to int
hex()
integer to hexade­cimal string
oct()
integer to octal string
tuple()
convert to a tuple
set()
type after converting to set
list()
any data type to a list type
dict()
a tuple of order (key,v­alue)to dict
str()
int to str
comple­x(r­eal­,imag)
real numbers to comple­x(r­eal­,imag) number
 

Byte Obj vs String

init str
a = 'lol'
init byte obj
b= b'lol'
a.enco­de(­'AS­CII­'),­b.d­eco­de(­'AS­CII')