COMP10001 MST Summary
COMP10001 MST Summary
COMMENTING
# single line comment Single-line comment
** exponent
% modulus/remainder
// floor/integer division
/ division
* multiplication
!= not equal to
and
or
CONDITIONAL
if <condition1>:
<statements/operations to be executed if condition1 is True>
elif <condition2>:
<statements/operations to be executed if condition2 is True>
...
elif <conditionx>:
<statements/operations to be executed if conditionx is True>
else:
<statements/operations to be executed if all conditions are False>
WHILE LOOP
while <condition>:
<statements/operations to be executed while condition is True>
FOR LOOP
# with range()
for i in range(<int>):
<statements/operations to be executed if i is less than <int>>
FUNCTIONS
CONSTANT = 0 # declare constants before all functions
def <function-name>(<parameters>):
<function-body>
DATA TYPES
INTEGERS
f-strings
Part Explanation
Format_code (default=auto)
f float
s string
g ‘optimal’ float
d integer
c Unicode character
FLOAT
BOOLEAN
LIST
TUPLE
DICTIONARY
SETS
GENERAL METHODS/FUNCTIONS
type(object) find out type of object
len(str/list/tuple/set/dict) used to find number of characters in a
string or elements in a list/tuple/set
or number of key-value pairs in a dict