= y = 18
x print(id(x),id(y), id(18))
is y x
140711489444032 140711489444032 140711489444032
True
Works as a hidden inheritence
Something like a factory. Ultimately, type creates the objects, apparently.
class Meta(type):
def __new__(mcs, name, bases, class_dict, **kwargs):
class_ = super().__new__(mcs, name, bases, class_dict)
if kwargs:
for name, value in kwargs.items():
setattr(class_, name, value)
return class_
class testMeta(object, metaclass=Meta, attr1=True, attr2='42'):
def __init__(self, name, value):
self.name = name
self.value = value
dir(testMeta(" ",10))[-4:]
['attr1', 'attr2', 'name', 'value']
proper dictionary manipulation
Accessing with default value.
Using KeyError
to set new keys.
Since python 3.9 the union operator |
works in dicts as well. Since I am currently on 3.8, here’s a union of sets, but you get the gist.
It is possible to append :character[<^>]number
while formatting a string to include a character
multiple times so as to the final string have size of at least number
f-strings can be formatted to insert variables/expressions before equal sign and value.