Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python 3.10 is Released
#1
Release Python 3.10.0
One big new thing is the new switch/case statements version on steroid💪
It's called Structural Pattern Matching
A quick test:
vehicle = 'Taxi'
match vehicle:
    case 'Car':
        print('Drive yourself')
    case 'Bus'|'Taxi':
        print('Public transport')
    case _:
        print(f'{vehicle!r} not in record'
Output:
Public transport
status_code = 200
match status_code:
    case 400|401|403 :
        print("Bad request")
    case 200:
        print("Request Ok")
    case _:
        print("Something else bad happened")
Output:
Request Ok
So as excepted and | is used as as or pattern.
A nice short way to specify an isinstance() check.
my_string = 'Hello'
#my_string = 5
match my_string:
    case int():
         print("I'm a integer")
    case str():
         print("I'm a string")
Output:
I'm a string

Better error messages
>>> lst = [1, 2, 3
  File "<stdin>", line 1
    lst = [1, 2, 3
          ^
SyntaxError: '[' was never closed
>>> foo(x, z for z in range(10), t, w)
  File "<stdin>", line 1
    foo(x, z for z in range(10), t, w)
           ^^^^^^^^^^^^^^^^^^^^
SyntaxError: Generator expression must be parenthesized
def foo():
    if pin:
    x = 2
    else:
        x = 100
Output:
File "C:\Python310\indent.py", line 3 x = 2 ^ IndentationError: expected an indented block after 'if' statement on line 2
Advice when error,eg typo ect...
>>> liist('hello')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'liist' is not defined. Did you mean: 'list'?
>>> list('hello')
['h', 'e', 'l', 'l', 'o']
>>> from datetime import date
>>>
>>> data(2020, 5, 17))
  File "<stdin>", line 1
    data(2020, 5, 17))
                     ^
SyntaxError: unmatched ')'
>>> data(2020, 5, 17)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'data' is not defined. Did you mean: 'date'?
>>> date(2020, 5, 17)
datetime.date(2020, 5, 17)
Larz60+ likes this post
Reply
#2
YouTube - Python 3.10 Release Stream — with Pablo Galindo
snippsat and Larz60+ like this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  PAGE 8.0 RELEASED rob101 4 777 Jan-06-2024, 02:07 PM
Last Post: rob101
Star Nodezator v1.4 released! (Python node editor in the public domain) KennedyRichard 0 921 Sep-04-2023, 01:42 PM
Last Post: KennedyRichard
Star Nodezator (free Python node editor) released to the public domain! KennedyRichard 4 2,181 Jun-24-2022, 09:49 AM
Last Post: Larz60+
  Kivy 2.0.0 released buran 1 2,773 Dec-10-2020, 01:51 PM
Last Post: snippsat
  3.9.0 released today Larz60+ 0 1,681 Oct-05-2020, 09:51 PM
Last Post: Larz60+
  Python 3.8.0 is released perfringo 2 3,777 Oct-15-2019, 10:53 AM
Last Post: perfringo
  Python 3.7.1 has been released DeaD_EyE 0 2,421 Oct-22-2018, 07:57 AM
Last Post: DeaD_EyE
  Python 3.7 and also Python3.6.6 released buran 0 2,837 Jun-28-2018, 04:52 AM
Last Post: buran
  Python 3.701b released yesterday--who should install it and who shouldn't? league55 7 4,437 Feb-02-2018, 08:11 AM
Last Post: DeaD_EyE
  qutebrowser v1.0.0 released dvs1 0 3,313 Oct-18-2017, 11:57 PM
Last Post: dvs1

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020