[Tutor] Beginners question
Cameron Simpson
cs at cskk.id.au
Mon Apr 6 01:52:19 EDT 2020
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>
More information about the Tutor
mailing list