I am a newbie in Python and playing around with the classes right now,
Have a look at this simple code,
class Testing:
BB_Key_Length = {256 : 240}
#method __init__() is a special method, which is called class constructor or initialization method that
#Python calls when you create a new instance of this class.
def __init__(self, key_length):
self._key_length = key_length
self._n = int(key_length / 8)
if key_length in self.BB_Key_Length:
self._b = self.BB_Key_Length[key_length]
print(self._b)
Object1 = Testing(200)
print(Testing.BB_Key_Length)
on line 13, it is written that, print(self._b) which is also inside the __init__ function but why the value of self._b is not printing when I am creating the object
Object1 = Testing(200)
All I want is to print the value of self._b which i couldn't be able to print
if key_length in self.BB_Key_Length. If that condition isn't met, the lineprint(self._b)never happens. And indeed,key_lengthwill be equal to 200, and 200 is not in the dictionary{256 : 240}if 200 in self.BB_Key_Lengthjust checks whether there is a key inself.BB_Key_Lengthequal to 200. But there is only one key inself.BB_Key_Length, and that is 256.