Format 'String Literals' Flashcards
1
Q
How to Print line with variable output using fstring ?
A
name = ‘Hemant Kumar’
age = 32
print(f”{name:-{5}}”)
2
Q
How to set the padding between output of two variables with fstring ?
A
name = ‘Hemant Kumar’
age = 32
print(f”{name:{10}} {age:{5}}”)
3
Q
How to create a list of tuples and present it with f-string ?
A
profiles = [(‘Name’,’Age’,’Sex’),(‘Hemant’,34,’Male’),(‘Billu’,2,’Female’)]
for name,age,sex in profiles:
print(f”{name:{10}}{age:
4
Q
how to add space while presenting variables using f strings ?
A
print(f”Age:{age:{5}}”)