In [1]:
import sys
sys.version
Out[1]:
'3.8.3 (default, Jul  2 2020, 16:21:59) \n[GCC 7.3.0]'
In [1]:
val = "Hello"
In [11]:
print(f"the value is {val=}")
the value is val='Hello'
In [12]:
print(f"the value is {val = }")
the value is val = 'Hello'
In [13]:
num_val = 123
In [15]:
print(f"the value is {num_val%2 = }")
the value is num_val%2 = 1
In [22]:
val = "hello😂"
In [24]:
print(f"the value is {val}")
the value is hello😂
In [23]:
print(f"the value is {val!a}")
the value is 'hello\U0001f602'
In [25]:
print(f"the value is {val!r}")
the value is 'hello😂'
In [27]:
print(f"the value is {repr(val)}")
the value is 'hello😂'
In [28]:
num_val = 123.4567
In [29]:
import datetime
In [30]:
now = datetime.datetime.now()
In [32]:
print(f"{now}")
2021-06-22 09:35:44.628499
In [35]:
print(f"{now:%Y-%d-%d}")
2021-22-22
In [36]:
print(f"{now=:%Y-%d-%d}")
now=2021-22-22
In [38]:
print(f"{num_val:.2f}")
123.46
In [39]:
print(f"{num_val=:.2f}")
num_val=123.46
In [54]:
class MyClass:
    def __init__(self):
        return None
    def __format__(self, param):
        print(f"Recieve {param=!r}")
        return "AAA"
In [55]:
print(f"{MyClass()}")
Recieve param=''
AAA
In [56]:
print(f"{MyClass(): blah blah %%MYFORMAT%%}")
Recieve param=' blah blah %%MYFORMAT%%'
AAA
In [ ]: