Created
September 24, 2021 06:56
-
-
Save SaraM92/f1a3ca687d82544cd41878f09e85d027 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Formatting strings with f string. | |
str_val = 'books' | |
num_val = 15 | |
print(f'{num_val} {str_val}') # 15 books | |
print(f'{num_val % 2 = }') # 1 | |
print(f'{str_val!r}') # books | |
#Dealing with floats | |
price_val = 5.18362 | |
print(f'{price_val:.2f}') # 5.18 | |
#Formatting dates | |
from datetime import datetime; | |
date_val = datetime.utcnow() | |
print(f'{date_val=:%Y-%m-%d}') # date_val=2021-09-24 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment