Reputation: 18743
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
Upvotes: 0
Views: 67
Reputation: 49816
why the value of self._b is not printing when I am creating the object
Object1 = Testing(200)
Because the print statement is inside an if statement, which is false because 200 is not a key in the dict self.BB_Key_Length
.
Upvotes: 1