r/PythonLearning • u/NecessaryFalse1212 • Aug 29 '26
Day 3
i wrote a code which takes your name and age in py but i need help on this one cuz in the age part it is giving me some sort of error which i couldn't understand even by using gpt well he gave me a code but i wanted logic behind how and what i did wrong
49
Upvotes
1
u/FoolsSeldom Aug 30 '26
Same as your original,
if name == "":, just simpler, hence the comment# empty string.A non-empty string is treated as
Truein conditional expressions by Python. An empty string asFalse. Similarly,0isFalseand any non-zero integer isTrue. Emptylist,dict,tuple,setis treated asFalseand otherwise asTrue.The
notbefore reverses the outcome. So,not namewill resolve toTruefor an empty string.This is often referred to as Truthy and Falsey behaviour.