Python Learning Series · @onlysamarrr · Day 7 / 30
Day 7 teaches f-strings and slicing. An f-string puts variables inside text with {}, and slicing [start:end:step] takes part of a string. Indexing starts at 0.
Phase: Beginner · Reels: 31/450 – 35/450
Day 7 teaches f-strings and slicing. An f-string puts variables inside text with {}, and slicing [start:end:step] takes part of a string. Indexing starts at 0.
name = "Arhan"
score = 92.456
s = "python"
print(f"{name}: {score:.1f}%")
print(f"{name=}")
print(s[0], s[-1])
print(s[0:3])
print(s[::2])
print(s[::-1])
Arhan: 92.5% name='Arhan' p n pyt pto nohtyp
Formatting messages, prices and reports, and reversing or slicing text, all use f-strings and slicing.
Select (tick) an option, then tap Check answer to see instantly whether your answer is right or wrong, with an explanation. You can change your answer and check again.
Q1. In s = "python", what is s[1]?
Q2. What does "python"[::-1] give?
Q3. What does f"{2 + 3}" produce?
| 31/450 | Concept | f-string se formatting |
| 32/450 | Live demo | Slicing [start:end:step] |
| 33/450 | Common mistake | Index 0 se start hota |
| 34/450 | Quiz | Quiz: string reverse karo |
| 35/450 | Interview / real life | Interview: s[::-1] kaise kaam karta |