CheatSheet Python
CheatSheet Python
** Exponent 2 ** 3 = 8
% Modulus/Remainder 22 % 8 = 6
// Integer division 22 // 8 = 2
/ Division 22 / 8 = 2.75
* Multiplication 3*3=9
- Subtraction 5-2=3
+ Addition 2+2=4
var += 1 Addition var = var + 1
var -= 1 Subtraction var = var - 1
var *= 1 Multiplication var = var * 1
var /= 1 Division var = var / 1
var %= 1 Modulus/Remainder var = var % 1
Data Type Examples
Integers -2, -1, 0, 1, 2, 3, 4, 5
Floating-point numbers -1.25, -1.0, --0.5, 0.0, 0.5, 1.0, 1.25
Strings 'a', 'aa', 'aaa', 'Hello!', '11 cats'
print(*objects, sep=' ', end='\n', file=None, flush=False)
Function 1st argument 2nd argument 3rd argument
print() *objects, sep=' ', end='\n',
The thing to be printed. Can be Separator between End after all objects are
Print objects to the text
basically anything: string, float, objects printed. Default printed. Default 'New
stream file
variable, list, dictionary… 'space' line'
>>> print("car")
car
>>> print(*"car")
car
>>> print(range(1,5))
range(1, 5)
>>> print(*range(1,5))
1234
4th argument 5th argument
file= None, flush=False
string.center(length, character)
- length is required.
center() Returns a centered string
- character is optional and default is
" " (space).
format_map(
Formats specified values in a string
)
Searches the string for a specified
index() value and returns the position of
where it was found
Returns True if all characters in the
isalnum()
string are alphanumeric
Returns True if all characters in the
isalpha()
string are in the alphabet
Returns True if all characters in the
isascii()
string are ascii characters
Returns True if all characters in the
isdecimal()
string are decimals
Returns True if all characters in the
isdigit()
string are digits
Returns True if the string is an
isidentifier()
identifier
Returns True if all characters in the
islower()
string are lower case
Returns True if all characters in the
isnumeric()
string are numeric
Returns True if all characters in the
isprintable()
string are printable
Returns True if all characters in the
isspace()
string are whitespaces
Returns True if the string follows the
istitle()
rules of a title
Returns True if all characters in the
isupper()
string are upper case
Converts the elements of an iterable
join()
into a string
Returns a left justified version of the
ljust()
string
lower() Converts a string into lower case
Returns a left trim version of the
lstrip()
string
Returns a translation table to be
maketrans()
used in translations
Returns a tuple where the string is
partition()
parted into three parts
Returns a string where a specified
replace() value is replaced with a specified
value