14. Functions and Code Reuse
def function1():
print("hello from function!")
function1()
class Character():
def __init__(self, health, damage, speed):
self.health = health
self.damage = damage
self.speed = speed
mage = Character(100, 30, 10)
priest = Character(80, 40, 20)
warrior = Character(120, 10, 5)
print(mage.health)
print(priest.damage)
print(warrior.speed)
def function(arg1, *args):
print("{} {}".format(arg1, " ".join([s for s in args])
function("function", "a", "b", "c")
def function2(**kwargs):
for a in kwargs:
print(a, kwargs[a])
function2(a="1", b="2", c="3", d="4")
v = 100
print(v) # Output: 100
def function():
global v # Calls variable "v" outside of the function
v += 1
print(v) # Output: 101