python multiline f string code example
Example 1: f string in python
name = "John Smith"
print(f"Hello, {name}")
name = "John Smith"
print("Hello, {}".format(name))
Example 2: multiline f string python
date = "01/31/1956"
time = "9:30 AM"
tags = ["high value", "high cost"]
text = "Hello"
return (
f'{date} - {time}\n'
f'Tags: {tags}\n'
f'Text: {text}'
)
return f'''{date} - {time},
Tags: {tags},
Text: {text}
'''
Example 3: python f string
>>> name = "Eric"
>>> age = 74
>>> f"Hello, {name}. You are {age}."
'Hello, Eric. You are 74.'
Example 4: python fstring
age = 12
name = "Simon"
print(f"Hi! My name is {name} and I am {age} years old")