isn't --- my_boolean -- in the given example considered as variable? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

isn't --- my_boolean -- in the given example considered as variable?

my_boolean=True print(my_boolean) o/p -- True # but when I assign it some other word , it shows error. also that when I change this variable name from my_boolean to my_bool , then also it shows error.

10th Aug 2016, 1:41 PM
Anuradha Bhatsange
Anuradha Bhatsange - avatar
4 Answers
+ 2
well, if you want the variable to be a boolean value then it can only store two valid values: True or False. if you want it to be of another type just remember to add quotes if its a string type. and the error when changing the name of the variable may be because you didn't update the name of the variable when its called within the print function.
10th Aug 2016, 2:50 PM
Rick
+ 1
you need to make true a string by adding quotes "true". or str(true)
10th Aug 2016, 1:54 PM
jouba
+ 1
my_boolean=True <--- line 1 print(my_boolean) <--- line 2 if you change only in line 2 or only line 1 the NameError occur for sure if you want to change the name of variable try both lines
30th Aug 2016, 6:27 PM
beauty1234
0
It worked for me changing it to my_bool. Just make sure you change the place holder and also when you do the print command
19th Aug 2016, 4:52 AM
Rykan
Rykan - avatar