1. Data Structure (and method) and Basic operation Flashcards
8 basic datatypes
int, float, bool, str
list, tuple, set, dict
list
[a,b,c]
ordered sequence of objects
tuple
(a,b,c)
ordered immutable sequence of objects
set
{a,b,c}
unordered unique objects
set cannot be retrieved by index
either cast it to a list or tuple unpacking
dictionary
{“k1”: a , “k2” : b}
unordered key:value pairs
key can be number
index: power of 2
2**2
Remainder: 7 mod 4
7%4
not equal
!=
and == means equal
integer division / floor division
// 11.9 // 3 = 3
line continuation
‘this is a \
line continuation’
block comment
’’’
abc
‘’’
may only work in Jupyer
line comment #abc
user input
myvar = input()
always returns string
create variable dynamically
for i in range(9):
exec(f”g{i} = Grid({i})”)
In place function
Act direct and does not return anything
List.sort() -> original list is sorted
cast to different data types
int(string) list(string) str(int) str(list) -> this is stupid set(list)