In [ ]:
def foo():
pass
def suma(a, b):
return a + b
print(foo())
print(foo)
print(suma(5, 10))
In [ ]:
def suma(a, b, c=5, d=10):
return a + b + c + d
print(suma(1, 2))
In [ ]:
def suma(a, b, c=5, d=10):
return a + b + c + d
print(suma(1, 2, 3))
In [ ]:
def suma(a, b, c=5, d=10):
return a + b + c + d
print(suma(1, 2, d=5, c=5))
In [ ]:
def suma(a, b, c=5, d=10):
return a + b + c + d
print(suma(1, d=5, c=5))
In [ ]:
def suma(a, b, c=5, d=10):
return a + b + c + d
print(suma(1, d=5, e=5))
In [ ]:
def suma(a, b, c=5, d=10):
return a + b + c + d
liczby = {
"c": 5,
"d": 10
}
print(suma(1, 2, **liczby))
In [ ]:
def suma(a, b, c=5, d=10):
return a + b + c + d
liczby = {
"c": 5,
"e": 10
}
print(suma(1, 2, **liczby))
In [ ]:
def suma(a, b, **kwargs):
print(kwargs)
print(type(kwargs))
return a + b + sum(kwargs.values())
liczby = {
"c": 5,
"e": 10
}
print(suma(1, 2, **liczby))
In [ ]:
def suma(a, b, **kwargs):
print(kwargs)
return a + b + sum(kwargs.values())
liczby = {
"c": 5,
"e": 10
}
print(suma(1, 2, a=5))
In [ ]:
def suma(a, b, **kwargs):
print(kwargs)
return a + b + sum(kwargs.values())
liczby = {
"c": 5,
"e": 10
}
print(suma(1, 2, liczba1=1, liczba2=2, liczba3=3))
In [ ]:
def suma(a, b, *args, **kwargs):
print(kwargs)
print(args)
return a + b + sum(args) + sum(kwargs.values())
liczby = {
"c": 5,
"e": 10
}
print(suma(1, 2, 3, liczba1=1, liczba2=2, liczba3=3))
In [ ]:
def suma(a, b, *args, **kwargs):
print(kwargs)
print(args)
return a + b + sum(args) + sum(kwargs.values())
liczby = {
"c": 5,
"e": 10
}
print(suma(1, 2))
In [ ]:
def akumulator(liczby=[]):
liczby.append(1)
return liczby
akumulator()
akumulator()
print(akumulator())
print(akumulator([]))
print(akumulator())
In [ ]:
def akumulator(liczby=[]):
liczby.append(1)
return liczby
akumulator()
akumulator()
akumulator()
akumulator([])
akumulator()
print(akumulator.__defaults__)
In [ ]:
def akumulator(liczby=None):
if liczby is None:
liczby = []
liczby.append(1)
return liczby
akumulator()
akumulator()
print(akumulator())
print(akumulator([]))
print(akumulator())
In [ ]:
_no_value = object()
def akumulator(liczby=_no_value):
if liczby is _no_value:
liczby = []
liczby.append(1)
return liczby
akumulator()
akumulator()
print(akumulator())
print(akumulator([]))
print(akumulator())
In [ ]:
def foo():
return 1, 2, 3, 4, 5
a, b, c, *d = foo()
print(a)
print(b)
print(c)
print(d)
In [ ]:
def foo():
return 1, 2, 3, 4, 5
_, *d, _ = foo()
print(d)
In [ ]:
def foo():
lista = [1, 2, 3, 4, 5]
return lista
a, b, c, *d = foo()
print(a)
print(b)
print(c)
print(d)
In [ ]:
x = lambda x: x + 5
a = x(10)
print(a)
In [ ]:
x = lambda x, y: x + 5 + y
a = x(10, 5)
print(a)
In [ ]:
x = lambda: 10
a = x()
print(a)
In [ ]:
x = 10
def foo():
print(x)
def bar():
x = 5
print(x)
def foobar():
global x
x = 1
print(x)
foo()
bar()
print(x)
foobar()
print(x)
In [ ]:
x = 10
class Point():
a = x
print(":)")
def foo(self):
print(self.a)
self.a = 5
print(self.a)
def bar(self):
print(x)
print(x)
Point().foo()
print(x)
x = 7
Point().bar()