<jupyter_start><jupyter_text>FunctionsFunctions are first class citizens in Python! Python is a good fit for functional programming paradigms... More on that another day.<jupyter_code># define a function using def functionName(variable1, variable2):
def myFirstFunction():
    print("Ran the function!")
    
# call the function
myFirstFunction()
# implement a return statement
def mySecondFunction():
    return 100

mySecondFunction()

# pass in parameters
def myThirdFunction(a, b=1):
    return a/b

myThirdFunction(100, 10)
# pass in parameters
def myFourthFunction(a:int, b:int):
    return a, b

#myFourthFunction(100, 10)

myFourthFunction(("abc" + "def"), 10)<jupyter_output><empty_output><jupyter_text>`*Args` and `**Kwargs`<jupyter_code># pass in the parameters to the previous functions using a dict and **
# aka "Kwargs"
vals = {"a":1000, "b":10}
myThirdFunction(**vals)
# Pass in a variable number of arguments using a "*"
# aka "*Args"
def myFourthFunction(a, *args):
    print(a)
    for v in args:
        print(v)

myFourthFunction("100", "1", "2", "3", "4")
def MultipleReturn():
    a = 1
    b = 2
    c = 3
    return a, b, c

MultipleReturn()
x, y, z = MultipleReturn()
y<jupyter_output><empty_output><jupyter_text>--- ClassesPython is actually Object Orientated, so it is easy to define classes<jupyter_code># Create a class
class myClass():
    
    # constructor method
    def __init__(self, val1=None, val2=None):
        self.prop1 = val1
        self.prop2 = val2
        
    # simple example method   
    def product(self):
        return self.prop1 * self.prop2

    
    
# Create an instance of the class
x = myClass(100, 20)

# Print the properties and the output of the "product" method
print(x.prop1)
print(x.prop2)
print(x.product())
# Python classes also have things like class variables, inheritance....but this session is meant to be < 1 hour!<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup