Python syntax Flashcards
Data types - in python syntax
Integer
Real
Boolean
Character
int
float
bool
str
Convention of data types into Integer Real Boolean List
Conversion is used to transform the data types of the contents of a variable using int(), str(), float(), bool() or list().
How constants conventionally named
Constants are conventionally named in all uppercase characters.
A structured data type is a sequence of items, which themselves are typed. Sequences start with an index of __.
Zero
Array vs record in python explanation + syntax
Array - A sequence of items with the same (homogeneous) data type list
Record - A sequence of items, usually of mixed (heterogenous) data types list
Arithmetic operators:
division multiplication exponentiation addition subtraction integer division modulus
/ * ** \+ - // %
Relational operators
equal to not equal to greater than greater than or equal to less than less than or equal to
== != > >= < <=
Logical/Boolean operators
- both sides of the test must be true to return true
- either side of the test must be true to return true
- inverts
and
or
not
Assignment
=
=
Selection —- all
if :
if :
else:
if :
elif :
else:
Repetition
Pre-conditioned loop. This executes while is true.
while :
Iteration -
Executes for each element of a data structure, in one dimension
for in :
Count-controlled loop. Executes a fixed number of times, based on the numbers generated by the range function
for in range (, ):
for in range (, ):
In range - what is inclusive and what is exclusive ?
for in range (, ):
Count-controlled loop. Executes a fixed number of times, based on the numbers generated by the range function
influences the numbers generated by the range function
for in range (start, stop, step):
How to define a procedure with no parameters
def ():
How to define a procedure with parameters
def (, ):
How to define a function with no parameters
def ():
return ()