191. Python’s F-strings Internals
1
Basic f-string Syntax
name = "Alice"
age = 25
print(f"My name is {name} and I am {age} years old.")2
f-strings Use str.format() Internally
str.format() Internallyname = "Bob"
age = 30
# Equivalent f-string and str.format()
f_string = f"My name is {name} and I am {age} years old."
format_string = "My name is {} and I am {} years old.".format(name, age)
print(f_string)
print(format_string)3. f-strings Evaluate Expressions
4. f-strings Use __format__() Internally
__format__() Internally5. f-strings are Faster than str.format()
str.format()Last updated