[Tutor] Beginners question

Gary gffaulkner at gmail.com
Mon Apr 6 05:11:22 EDT 2020


Syntax error and multiple statement vs single statement partially sorted
thanks when using IDLE. 

Thanks

Gary Faulkner
+27661755182 (W)

-----Original Message-----
From: Tutor [mailto:tutor-bounces+gffaulkner=gmail.com at python.org] On Behalf
Of Cameron Simpson
Sent: Monday, 06 April 2020 07:52
To: tutor at python.org
Subject: Re: [Tutor] Beginners question

On 05Apr2020 23:50, Alan Gauld <alan.gauld at yahoo.co.uk> wrote:
>Looking at the code below, does this only work with
>format strings? Or was it only introduced with
>format strings? I'm still on 3.6 so that may be why
>I've never seen it before...
>
>> class Person:
>>     def __init__(self, first, last):
>>         self.first = first
>>         self.last = last
>>
>>     def __format__(self, spec):
>>         first = self.first
>>         last = self.last
>>
>>         if spec == "debug":
>>             return f"{first=}, {last=}"
>
>> print(f"debug: {p:debug}")
>
>> debug: first='Alan', last='Gauld'

If you mean the "{first=}" notation, that is very recent. Maybe 3.8?

Cheers,
Cameron Simpson <cs at cskk.id.au>
_______________________________________________
Tutor maillist  -  Tutor at python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list