Skip to content

Replace % with f-string in basics/modules.md #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions basics/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,8 @@ for thing in things:
```

Measure how long it takes for the user to answer a question.
The `%.2f` rounds to 2 decimals, and you can find more formatting
tricks [here](https://pyformat.info/).
The `{:.2f}` rounds to 2 decimals, and you can find more formatting
tricks [here](https://docs.python.org/3/tutorial/inputoutput.html#formatted-string-literals).

```python
import time
Expand All @@ -381,7 +381,7 @@ end = time.time()
difference = end - start

if answer == '3':
print("Correct! That took %.2f seconds." % difference)
print(f"Correct! That took {difference:.2f} seconds.")
else:
print("That's not correct...")
```
Expand Down Expand Up @@ -410,7 +410,7 @@ Check what a path points to.
import os
import sys

print("You are currently in %s." % os.getcwd())
print(f"You are currently in {os.getcwd()}.")

while True:
path = input("A path, or nothing at all to quit: ")
Expand Down