Python Flashcards
Week 1.2, 1.3, 1.4, 1.5, 1.6 (36 cards)
variable
a named location in memory that stores a value which can be changed during execution
naming rules of variables
- no spaces, symbols
- start with a letter
- don’t use reserved rules
name some string functions
- capatalise()
- count()
- find()
- index()
- isalnum()
- isalpha()
- lower()
- upper()
syntax for f-strings
print(f”Name:{name}, Age:{name}, Heigt:{name}”)
truthy values
- non-0 numbers
- non-empty strings
- non-empty data structures
falsey values
- 0
- none (python equivalent to Null)
- empty string
- empty data structures
match-case statement
list syntax
[]
list functions
- append(item)
- insert(index, item)
- pop(index)
- remove(item)
- index(item)
- clear()
- reverse()
- sort()
tuple definition
ordered, one-dimensional array of objects that is immutable meaning once it is assigned it cannot be changed
tuple functions
- count(item)
- index(item)
tuple syntax
()
set syntax
{}
set definition
an un-ordered, one-dimensional array of object
- can’t index items
- set is mutable BUT set data is immutable
- set data is unique - no duplicates
- does not all have to be of the same time
set functions
- union(setB)
- intersection(setB)
- difference(setB)
- add(item)
- discard(item)
dictionary definition
ordered, one-dimensional array of key:value pairs
- the key is immutable & can be used to index values in the dict
dict functions
- clear()
- get(key)
- items()
- keys()
- pop(key)
- values()
break
immediately exits a loop
continue
jump directly to the while statement
else
excuted once the loop ends
parameteres of in range()
in range(start, stop, loop)
list comprehension
newlist = [expression for item in data_structure if logical_condition]
statement to strip and and read a file
list = [line.strip(“ “) for line in list]
docstring definition
first statement in a module, function, class ore method definition