Python
Python
By Phway
Data type changing (can or can’t)
Can Can’t
Float to int
String to int (numbers) String to int (words)
Bool to int Complex to int
Float to int None to int
String to float (numbers) String to float (words)
Int/float to complex string to complex (words)
String to complex (numbers) None to complex
To string/bool – everything
Bool to complex
printing format
Normal = print(“……………{var}……………….{var}…………….”)
F = print(f“………………..{var},,,,,,,,,,{var}”)
% = print(“………………..%…………………..%,,,,,,,,,,,,,,,,%”.%(var,var,var))
.format = print(“………………..{}…………………..{},,,,,,,,,,,,,,,,
{}.format(var,var,var))
Operat ion
Update
var operation = number
+ (Add)
Example
- (Sub)
a = 4/ b = 3
* (Multiple)
a -=3 (1)
/ (Division with float)
a +=3 (7)
// (Division with integer)
b*=3 (9)
% (Rem)
b /=3 (0)
** (powder )
a *=1 (4)
Name Formula e Example
Printing a print(var[position:]) print(a[13:])
Substring
Removing
Whitespace From .strip()
Strings
Adding Newlines in
Python \n
Name Formula e Example
\t
Tabs
Add comment #
Multiple lines \
Name Formula e Example
var[position]
index
Add comment #
Multiple lines \
Keeping a group of data
List [ ]
Tuple ( )
Set { }
Dictationary { }
Element
List = [a,b,c,d,e]
Element
(no need to be the same data type)
Dictation ary
Key Name
(must be sting)
Repeat Order Index Mute
List
Tuple
Set
Dictationary
List
Index - var[position]
mute - var[position] = sth u wanna replace
list to tuple or set
var = tuple(var)
var = set(var)
Tuple
Index - var[position]
tuple to list or set
var = list(var)
var = set(var)
Set
set to list or tuple
var = list(var)
var =tuple(var)
Dictio nary
Index - var[position]
mute - var[position] = sth u wanna replace
L = [ - 2 , 0 , 9 , 5 , - 3 ]
wanna print a
group ?