f-strings
f-strings (format strings) are the best way to combine variables and text together.
EXAMPLE :
name = "Katie"
age = "28"
pronouns = "she/her"
print("This is {}, using {} pronouns, and is {} years old.".format(name, pronouns, age))
Local Variables :
EXAMPLE
name = "Katie"
age = "28"
pronouns = "she/her"
print("This is {name}, using {pronouns} pronouns, and is {age} years old. Hello, {name}. How are you? Have you been having a great {age} years so far".format(name=name, pronouns=pronouns, age=age))
The Power of f...
EXAMPLE:
name = "Katie"
age = "28"
pronouns = "she/her"
response = f"This is {name}, using {pronouns} pronouns, and is {age} years old. Hello, {name}. How are you? Have you been having a great {age} years so far"
print(response)
Alignment:
left = <, right = >, center = ^
EXAMPLE:
for i in range(1, 31):
print(f"Day {i: <2} of 30")
Comments
Post a Comment