- PyByte
- Posts
- Python 3.12 and a Python on the loose??!
Python 3.12 and a Python on the loose??!
Issue 0.1
from PyByte import news, trick_of_the_week, find_inspiration, funny
# Welcome to the PyByte!
đź‘‹ Hey, and thanks for joining PyByte, a quick way to inject Python into your week!
news()
Python 3.12.0 was released on October 2nd of this week! 🎉
For me, the biggest change is with f-strings!
f'I can't wait for the weekend!'
On Python 3.11 and before, this would fail because your f-string is wrapped with single quotes, and the word can’t also contains a single quote. To get around this, you would have to alternate single/double quotes depending on what your string contained like this:
>>> f"I can't wait for the weekend!"
f'This is the "best" newsletter!'
With Python 3.12 they’ve removed this limitation! Your f-string can now contain the same single or double quotes that the f-string is wrapped with!
This also means you can now nest f-strings (previously nearly impossible) 🤯!
products = {'apple': 0.5, 'banana': 0.25, 'cherry': 0.75}
message = f'Today's prices: {', '.join([f'{product}: ${price:.2f}' for product, price in products.items()])}.'
print(message)
Would successfully print Today's prices: apple: $0.50, banana: $0.25, cherry: $0.75.
trick_of_the_week()
Use the parse library to quickly parse information from strings!
import parse
chat_message = 'Alice: Hey, how are you?'
pattern = '{username}: {message}'
result = parse.parse(pattern, chat_message)
result['username'] # Alice
result['message'] # Hey, how are you?
find_inspiration()
A word for those of you who are playing the “catch up and keep up” game…
There is nothing to be afraid of. You are where you’re supposed to be. When you look back you will not wish you would’ve gone faster you will wish you could have been happier.
Worry is not your ally — acknowledge and re-orient. Celebrate those who are winning and throw yourself headlong into what inspires & motivates you.
funny()
See you next week.
Joel