-
-
Save up1/87aac00e97f7506593e03b46283518bf to your computer and use it in GitHub Desktop.
Hello Python 3.14
This file contains hidden or 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
| world = "World" | |
| template = t"Hello, {world}" | |
| print(type(template)) | |
| print(list(template)) | |
| print(template.strings) | |
| print(template.values) | |
| print(template.interpolations) | |
| # ผลการ run | |
| <class 'string.templatelib.Template'> | |
| ['Hello, ', Interpolation('World', 'world', None, '')] | |
| ('Hello, ', '') | |
| ('World',) | |
| (Interpolation('World', 'world', None, ''),) |
This file contains hidden or 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
| # Upgrade Python | |
| $uv python upgrade 3.14 | |
| $uv venv --python 3.14 | |
| Using CPython 3.14 | |
| Creating virtual environment at: .venv | |
| Activate with: source .venv/bin/activate | |
| $python -V | |
| Python 3.14 | |
| $uv tool install ruff@latest |
This file contains hidden or 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
| def bad_try(): | |
| try: | |
| 1 / 0 | |
| except: | |
| return float("inf") | |
| finally: | |
| return 0 | |
| print(bad_try()) | |
| # ผลการ run | |
| SyntaxWarning: 'return' in a 'finally' block | |
| return 0 | |
| 0 | |
This file contains hidden or 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
| $python -m calendar 2025 10 | |
| October 2025 | |
| Mo Tu We Th Fr Sa Su | |
| 1 2 3 4 5 | |
| 6 7 8 9 10 11 12 | |
| 13 14 15 16 17 18 19 | |
| 20 21 22 23 24 25 26 | |
| 27 28 29 30 31 | |
| $python -m json users.json | |
| { | |
| "id": 1, | |
| "name": "Leanne Graham", | |
| "username": "Bret", | |
| "email": "[email protected]", | |
| "address": { | |
| "street": "Kulas Light", | |
| "suite": "Apt. 556", | |
| "city": "Gwenborough", | |
| "zipcode": "92998-3874", | |
| "geo": { | |
| "lat": "-37.3159", | |
| "lng": "81.1496" | |
| } | |
| }, | |
| "phone": "1-770-736-8031 x56442", | |
| "website": "hildegard.org", | |
| "company": { | |
| "name": "Romaguera-Crona", | |
| "catchPhrase": "Multi-layered client-server neural-net", | |
| "bs": "harness real-time e-markets" | |
| } | |
| } |
This file contains hidden or 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
| try: | |
| int("one") | |
| except ValueError, TypeError: | |
| print("Error caught !!") | |
| # ถ้า Run ใน Python 3.13 จะ error | |
| except ValueError, TypeError: | |
| ^^^^^^^^^^^^^^^^^^^^^ | |
| SyntaxError: multiple exception types must be parenthesized |
This file contains hidden or 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
| from compression import zstd | |
| import math | |
| data = str(math.pi).encode() * 20 | |
| compressed = zstd.compress(data) | |
| ratio = len(compressed) / len(data) | |
| print("Original size:", len(data)) | |
| print("Compressed size:", len(compressed)) | |
| print("Compression ratio:", ratio) |
This file contains hidden or 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
| $uvx [email protected] | |
| Python 3.14.0 free-threading build (main, Oct 10 2025, 12:32:44) [Clang 20.1.4 ] on darwin | |
| Type "help", "copyright", "credits" or "license" for more information. | |
| >>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment