Найти в Дзене
10 подписчиков

📑 Exploration of the Function locals()

📑 Task
1) What will the program print?
2) How can we change the 3rd line of the program so that
the function takes elements of the same dictionaries as arguments
but the program prints out only keys of these dictionaries?

def local_args(*args): return locals()
print(local_args(1, 2) == locals()['local_args'](1, 2))
print(local_args({'a': 1, 'b': 2}, {'b': 3})['args'])

📑 Answer
1) Two rows: True and ({'a': 1, 'b': 2}, {'b': 3})
2)

def local_args(*args): return locals()
print(local_args(*{'a': 1, 'b': 2}, *{'b': 3})['args'])
📑 Exploration of the Function locals() python-puzzles.blogspot.com/...tml 📑 Task 1) What will the program print?
Около минуты