+ 4

Why a=0

When i writhen this code: a=print("hello") print(a) Python give me next output: Hello None Why in 2 line python give me None explain pls

20th Jan 2021, 3:23 PM
Чесноков Максим
Чесноков Максим - avatar
3 Réponses
+ 14
It is because print() is a function that does NOT RETURN any value. a = print( "Executed first" ) print( a ) >> Executed first None - - - - - - - - - - - - - - - - - - - - - - This is just a representation of what's happening in the background (not the actual code of print function, just for representation) . def print(text): # some code to output in console print("Hello World") # The print() function does not return any value. Therefore None.
20th Jan 2021, 3:27 PM
noteve
noteve - avatar
+ 2
Thanks
20th Jan 2021, 3:30 PM
Чесноков Максим
Чесноков Максим - avatar
+ 1
You can try this to better understand...... print (print ('hello')) #output : hello None
21st Jan 2021, 8:45 PM
Surkhab Khan
Surkhab Khan - avatar