[Tutor] Python programming question related to Return/Print statement

Brenda Ives brendap at marketamerica.com
Wed Aug 19 08:12:41 EDT 2020


Thank you, very good information to know and in my programming language it would be "if not(last_name) then".  I will try that and see what error I get and if it would have led me to try that simple solution.



Brenda



-----Original Message-----
From: Tutor <tutor-bounces+brendap=marketamerica.com at python.org> On Behalf Of Dennis Lee Bieber
Sent: Monday, August 17, 2020 11:44 AM
To: tutor at python.org
Subject: Re: [Tutor] Python programming question related to Return/Print statement



On Mon, 17 Aug 2020 12:53:54 +0000, Brenda Ives <brendap at marketamerica.com<mailto:brendap at marketamerica.com>> declaimed the following:





>

>def format_name(first_name, last_name):

>

>    # return "Name: " + first_name + ", " + last_name

>

>    if last_name is '':



                "is" tests that the two are exactly the same object, it does not test if they are equal value. The Python interpreter /might/ cache short strings for re-use, but this behavior can not be relied upon if strings become longer than some amount.



                Also, Python considers "empty" strings as False, so this can be written as just



                if not last_name:



(that also applies to empty lists and dictionaries)





--

                Wulfraed                 Dennis Lee Bieber         AF6VN

                wlfraed at ix.netcom.com<mailto:wlfraed at ix.netcom.com>    http://wlfraed.microdiversity.freeddns.org/



_______________________________________________

Tutor maillist  -  Tutor at python.org<mailto:Tutor at python.org>

To unsubscribe or change subscription options:

https://mail.python.org/mailman/listinfo/tutor


More information about the Tutor mailing list