Python definitions

  1. Python variables are defined as

    x = 42
    s = 'abc'
    pi = 3.14
    
  2. Python functions are defined as

    def convert(f):
      return 5/9 * (f-32)
    
    • There must be an explicit return to return the result.
    • Note also how the body of the function is indented.
  3. return returns and print prints.

    def add3return(n):
        return n + 3
    
    def add3print(n):
        print(n + 3)
    
    7 + add3return(5)
    
    7 + add3print(5)  # fails!
    

Author: Breanndán Ó Nualláin <o@uva.nl>

Date: 2025-09-04 Thu 08:55