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}}”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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}}”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

how to add space while presenting variables using f strings ?

A

print(f”Age:{age:{5}}”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly