marcov4lente
3/28/2017 - 1:35 PM

Python notes

Python notes

Variables

Booleans

Booleans are case sensative, therefore true is not True

var = True
var = False

Mathematical operations

Exponentiation

number = 2**3

number == 8

General

Comments

# This is a comment line!

"""
  This is
  a comment
  Block
"""

Functions

Defining a basic function

def functionName(int)
  sum = int + 2
  return sum

Calling a basic function

functionName(int)

Function arguments

All function arguments are passed by reference. It means if you change what a parameter refers to within a function, the change also reflects back in the calling function.

Function argument types

  • Required arguments
  • Keyword arguments
  • Default arguments
  • Variable-length arguments

Required arguments

Mandatory arguments that have to be passed to the function.

def functionName(int)
  sum = int + 2
  return sum

Keyword arguments

def functionName(name, value)
  sum = int + 2
  return sum
  
functionName(value = 24, name = 'tralala')

Default arguments

Non mandatory arguments that default to a specified value.

def functionName(int = 1)
  sum = int + 2
  return sum

Variable-length arguments