print()
, execution order len()
, string operations/indexing/slicing, type conversion: int()
, str()
, float()
min()
, max()
, round()
, help()
, runtime errors (exceptions), syntax errors mass = 4.2
if mass > 3:
print(mass, ' is large')
if mass < 2:
print(mass, ' is small')
if 2 <= mass <= 3:
print(mass, ' is just right')
def print_greeting():
print ("Hello!")
def print_personalised_greeting(name):
print ("Hello "+name)
pressure = 103.9
def adjust(temperature):
new_temperature = temperature*1.43/pressure
Bonus end note: Programming good practice
Document your code with docstrings
def calc_bulk_density(mass,volume):
"Return dry bulk density = powder mass / powder volume."
return mass / volume
What are the other two types of code documentation you can use?
Focus on readability
spam(ham[1], {eggs: 2})
spam( ham[ 1 ], { eggs: 2} )
x
, p
etc and expect the reader to know what they mean!)Think about reproducibility
Reproducibility is more complex and difficult than you might think..
One straight-forward thing you can do is print the version number for each package you import using print(packagename.__version__)