Colab

def generic_func(*args, **kwargs):
    print('the positional args are:', args)
    print('the keyword args are:', kwargs)
    


generic_func()

the positional args are: ()
the keyword args are: {}
generic_func("one", "two", "three", blah=1, moshe=2, test=[1,2,3])

the positional args are: ('one', 'two', 'three')
the keyword args are: {'blah': 1, 'moshe': 2, 'test': [1, 2, 3]}
len([1,2,3], [1,2,3])


    ---------------------------------------------------------------------------

    TypeError                                 Traceback (most recent call last)

    <ipython-input-6-7407188aa4f7> in <module>
    ----> 1 len([1,2,3], [1,2,3])
    

    TypeError: len() takes exactly one argument (2 given)


print(1,2,3,4,5,6,7,8,1,2,34,25,4,5432,5432,5432,5432,5432)

1 2 3 4 5 6 7 8 1 2 34 25 4 5432 5432 5432 5432 5432
def test():
    class ToldYou:
        pass
    import math
    x = 10
    def inner():
        print('in inner func')
    return inner
    

def make_str_factory(s):
    
    def str_factory():
        return s
    
    return str_factory
    

smiley_factory = make_str_factory('😊')
hello_factory = make_str_factory('hello')

smiley_factory.__closure__

(<cell at 0x011302D0: str object at 0x010FF758>,)
dir(smiley_factory)

['__annotations__',
 '__call__',
 '__class__',
 '__closure__',
 '__code__',
 '__defaults__',
 '__delattr__',
 '__dict__',
 '__dir__',
 '__doc__',
 '__eq__',
 '__format__',
 '__ge__',
 '__get__',
 '__getattribute__',
 '__globals__',
 '__gt__',
 '__hash__',
 '__init__',
 '__init_subclass__',
 '__kwdefaults__',
 '__le__',
 '__lt__',
 '__module__',
 '__name__',
 '__ne__',
 '__new__',
 '__qualname__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__setattr__',
 '__sizeof__',
 '__str__',
 '__subclasshook__']
hello_factory()

'hello'
class Factory:
    def __init__(self, value):
        self.value = value
        
    def make(self):
        return self.value

smiley_factory = Factory('😊')
smiley_factory.make()

'😊'