Python 3.8 tso tawm

Qhov nthuav innovations tshaj plaws:

  • Kev qhia ua haujlwm:

    Tus tshiab := tus neeg teb xov tooj tso cai rau koj los muab cov txiaj ntsig rau qhov sib txawv hauv cov kab lus. Piv txwv li:
    if (n := len(a)) > 10:
    print(f"Tej npe ntev dhau lawm ({n} ntsiab lus, xav tau <= 10)")

  • Cov lus sib cav nkaus xwb:

    Tam sim no koj tuaj yeem qhia meej qhov kev ua haujlwm tsis tuaj yeem dhau los ntawm lub npe sib cav syntax thiab qhov twg tsis tuaj yeem. Piv txwv:
    def (a, b, /, c, d, *, e, f):
    print(a,b,c,d,e,f)

    f(10, 20, 30, d=40, e=50, f=60) # OK
    f(10, b=20, c=30, d=40, e=50, f=60) # yuam kev, `b` tsis tuaj yeem yog lub npe sib cav
    f(10, 20, 30, 40, 50, f=60) # yuam kev, 'e' yuav tsum yog ib qho kev sib cav npe

    Qhov kev hloov pauv no muab cov neeg tsim tawm txoj hauv kev los tiv thaiv cov neeg siv ntawm lawv cov APIs los ntawm kev hloov pauv hauv cov npe sib cav.

  • Txhawb f-strings = rau tus kheej-documenting qhia thiab debugging:

    Ntxiv qab zib kom yooj yim rau kev debugging/logging lus.
    n = 42
    print(f'Hello world {n=}.')
    # yuav sau "Nyob zoo ntiaj teb n=42."

  • Kho cov lus tseem ceeb txuas ntxiv hauv qhov kawg thaiv (nws tsis ua haujlwm ua ntej).

Lwm yam:

  • Koj tuaj yeem qhia meej meej txog txoj hauv kev mus rau bytecode cache tsis yog lub neej ntawd __pycache__.
  • Debug thiab tso tawm tsim siv tib ABI.

Tau qhov twg los: linux.org.ru ua

Ntxiv ib saib