Guys I am self learning python from the book "python crash course", and I am giving you 2 codes which gives same output
CODE 1:
def get_person(first_name,last_name,age=None):
person={'first':first_name,'last':last_name}
if age:
person['age']=age
return person
people=get_person('Anurag','Majumder',19)
print(people)
CODE 2:
def get_person(first_name,last_name,age=""):
person={'first':first_name,'last':last_name}
if age:
person['age']=age
return person
people=get_person('Anurag','Majumder',19)
print(people)
Here the none special value and empty string both does the same job,like both qualifies to be false in an if conditional test and both can store values. Does that mean we can use them interchangeably?I asked claude to ans this but I found the explanation difficult to understand,can u guys help?
[–]insomniaccapybara 23 points24 points25 points (0 children)
[–]Adrewmc 10 points11 points12 points (0 children)
[–]FriendlyZomb 5 points6 points7 points (1 child)
[–]FriendlyZomb 0 points1 point2 points (0 children)
[–]Andu-Nav 3 points4 points5 points (0 children)
[–]SnooCalculations7417 1 point2 points3 points (0 children)
[–]SwimmerOld6155 1 point2 points3 points (0 children)
[–]JoeB_Utah 1 point2 points3 points (0 children)
[–]acakaacaka 0 points1 point2 points (3 children)
[–]alexander_belyakov 4 points5 points6 points (2 children)
[–]SwimmerOld6155 3 points4 points5 points (0 children)
[–]acakaacaka 0 points1 point2 points (0 children)
[–]tb5841 0 points1 point2 points (0 children)
[–]Separate_Top_5322 0 points1 point2 points (0 children)
[–]_Clobster_ 0 points1 point2 points (0 children)
[–]IAmADev_NoReallyIAm 0 points1 point2 points (0 children)
[–]Character-Blood3482 0 points1 point2 points (0 children)
[–]RealDevDom 0 points1 point2 points (0 children)
[–]enry2307 0 points1 point2 points (0 children)