Try Python 3.10 with CONDA

Feffery 2021-10-29 07:32:06
try python conda

1 brief introduction

Just a few days ago ,Python3.10 First official version of 3.10.0 Release , Previously, we only learned about some new features that may be added from various beta versions , In the official version , We were able to see the many new features it officially joined .

In this article, I will take you to learn how to pass conda Fast installation 3.10 The official version of Python, And experience some of its important new features .

2 Python 3.10 List of important features of the official version

If you already have it installed conda, Then go straight through conda-forge Of channel, Just use the following command line to create a new Python3.10 Official version of virtual environment :

conda create -n py310 python=3.10 -c conda-forge -y

After installation , Activate the environment to enter Python Of shell, You can see that the version is 3.10.0, What's outrageous is that I'm using pycharm After setting the environment , Brand new 3.10.0 The environment is recognized as 3.1( I'm really drunk ), So I switched to vscode demonstrate :

Let's experience some of its important new features ~

2.1 New structural pattern matching Syntax

Last time was Python Introducing new syntax and keywords is still async, And in this new version , The introduction of new keywords match And case, So as to help us in Python Used in other languages similar to switch The grammar of , The usage is shown in the following example , about match The value declared after , Each of the following case It will verify whether it is equal to its corresponding value , final case _ Medium _ representative Irrefutable Pattern, It's equivalent to a wildcard , But it is only allowed to be placed in Last One case in :

import sys
match sys.argv[1]:
case '1':
print(1)
case '2':
print(2)
case '3':
print(3)
case _:
print(' Other inputs ')

match-case Syntax with wildcards _, When entering a container type data structure , You can make some more free judgments :

import sys
# 1 New structural pattern matching Syntax
match sys.argv[1:]:
case ['1', '2', '3']:
print(' Branch 1')
case ['4', _, '6']:
print(' Branch 2')
case ['7', '8', _]:
print(' Branch 3')
case _:
print(' Beyond known options !')

More interesting , We can also use any custom variable name , stay match-case Auxiliary wildcard matching within the scope of , So as to achieve the effect similar to the following example :

import sys
# 1 New structural pattern matching Syntax
match (int(sys.argv[1]), int(sys.argv[2])):
case (0, 0):
print(" origin ")
case (0, y):
print(f"Y={y}")
case (x, 0):
print(f"X={x}")
case (x, y):
print(f"X={x}, Y={y}")
case _:
print(' Illegal input !')

Allied , Attribute values for the object , Similar general matching judgment can also be made , For more usage, you can refer to the following examples to expand :

import sys
class Demo:
x: int
y: int
demo = Demo()
demo.x = int(sys.argv[1])
demo.y = int(sys.argv[2])
# 1 New structural pattern matching Syntax
match demo:
case Demo(x=0, y=0):
print(" origin ")
case Demo(x=0, y=y):
print(f"Y={y}")
case Demo(x=x, y=0):
print(f"X={x}")
case Demo(x=x, y=y):
print(f"X={x}, Y={y}")
case _:
print(' Illegal input !')

2.2 Clearer error messages

stay Python3.10 in , For various common error types , The error prompt after executing the code is more clear , For example, here is 3.9 And 3.10 Compare the error output information for the same error :

2.3 Support bracket wrapped multi context manager

This feature is actually 3.9 It began to appear in , stay 3.10 Further improved in , Make the following usage legal ( And 3.7 Contrast ):

2.4 More convenient union type prompt settings

In the previous version , When we use multiple types of prompts , It has to be written like this :

from typing import Union, string
def some_funcion(flexible_parameter: Union[int, string]) -> Union[int, string]:
return flexible_parameter

And in the 3.10 in , Multi type union is no longer necessary Union, Use | Connect to , Very convenient :

from typing import string
def some_funcion(flexible_parameter: int | string) -> int | string:
return flexible_parameter

2.5 More accurate error code line location prompt

stay Python3.10 in , Error prompt for code , The prompt for the specific error line position is more accurate :


The above is the whole content of this paper , Welcome to discuss with me in the comments section .

Participation of this paper Tencent cloud media sharing plan , You are welcome to join us , share .

版权声明
本文为[Feffery]所创,转载请带上原文链接,感谢
https://pythonmana.com/2021/10/20211013191310329Z.html

  1. Python,前缀后缀相同时合并
  2. 关于#python#的问题:python
  3. 關於#python#的問題:python
  4. Python,前綴後綴相同時合並
  5. Questions sur # # Python #: Python
  6. Python, préfixe et suffixe combinés en même temps
  7. python manage.py shell无法运行,
  8. python manage.py shell無法運行,
  9. Le shell Python manage.py ne fonctionne pas,
  10. python中使用vscode Import 'matplotlib.pyplot' could not be resolved from source 问题
  11. [Chapter 11 of the full version] Python advanced crawler practice - system master Po anti climbing skills challenge high salary
  12. L'utilisation de vscode Import 'matplotlib.pyplot' en python ne peut pas être résolue à partir du problème source
  13. Python fusionne les deux listes et supprime les éléments dupliqués lors de la fusion
  14. [JS Reverse AES Reverse Encryption] python crawler combat, les jours sont de plus en plus décisifs
  15. 30 jeux Python. Je peux jouer à la pêche au travail pendant une journée.
  16. J'a i collecté un nouveau hit de liste en python, donc c'est un secret que quelqu'un d'autre peut devenir un magnat des médias!
  17. J'a i utilisé Python pour ramper à travers 5000 belles photos de papier peint, un jour oublié Premier amour!
  18. [Python planting system] the best green plant for your girlfriend. Girls love it when they see it! Attachment: should be able to feed - right??!
  19. [Python love guide] two small programs for sweetness burst table are released! Afraid you can't find someone?
  20. J'ai utilisé Python pour ramper 1000 lettres d'amour pour aider mon colocataire à exprimer les fleurs de classe, mais les inverser et les inverser... C'est le secret ultime des fleurs de classe!
  21. J'ai utilisé Python pour me connecter à la plus grande plate - forme de jeu au monde, et à quel point le cryptage steam est intelligent [code source inclus]
  22. python中列表转为矩阵后无法进行矩阵的乘法运算
  23. Python crawler Development and Learning full tutoriel 2nd Edition, banggan 100000 words [recommended Collection]
  24. Python crawler haut de gamme: microstore confus anti - décryptage
  25. La multiplication de la matrice ne peut pas être effectuée lorsque la liste est convertie en matrice en python
  26. Introduction to operators in python (Part 1)
  27. Are the dictionaries in Python ordered
  28. Introduction to dictionaries in Python
  29. List introduction in Python
  30. pandas比较两个dataframe特定数据列的数值是否相同并给出差值:使用np.where函数
  31. Python使用matplotlib绘制透明背景的可视化图像并保存透明背景的可视化结果(transparent background)
  32. Python self study notes -- basic grammar
  33. Python utilise matplotlib pour dessiner une image visuelle de l'arrière - plan transparent et enregistrer les résultats visuels de l'arrière - plan transparent
  34. Pandas compare les valeurs de deux colonnes de données spécifiques à dataframe et donne des valeurs de voyage: en utilisant la fonction np.where
  35. Comment configurer une application ASGI Django avec Postgres, nginx et uvicorn sur Ubuntu 20.04
  36. What are the advantages of Python and how to get started quickly
  37. Python self study notes -- basic data types
  38. Python code reading (Chapter 14): List Union
  39. Analyse statistique de la fonction de données des essais aléatoires Python
  40. Alien invasion project in Python application -- Aliens (Part 2)
  41. Python code reading (Chapter 14): List Union
  42. Lecture du Code Python (article 25): diviser les chaînes multilignes en listes
  43. Python self study notes -- operators
  44. Formation python - différences entre http et HTTPS
  45. Implementation of automatic timing comment function on Python CSDN platform
  46. python+tkinter+treeview子控件快捷键
  47. Raccourcis clavier pour les sous - contrôles Python + tkinter + treeview
  48. Analyse des données Python
  49. python+tkinter+treeview子控件快捷鍵
  50. Devine si je peux attraper Maotai avec la programmation python? Tout est ouvert à github
  51. À propos de pygame.display.set in Python Un petit problème avec mode ()
  52. Implementation of automatic timing comment function on Python CSDN platform
  53. python:dataframe进行iteritem遍历时如何将输出结果按照列分别输出为该列最后一行
  54. python:dataframe進行iteritem遍曆時如何將輸出結果按照列分別輸出為該列最後一行
  55. Python: comment le dataframe affiche les résultats de sortie par colonne à la dernière ligne de la colonne lors de la traversée de l'itemitem
  56. Écrivez un gadget de bureau pour votre fille préférée en python et elle dit que c'est génial!
  57. Introduction to closures in Python 3
  58. Global / nonlocal usage in Python 3
  59. Introduction to context manager in Python 3
  60. Common standard library random, python introductory tutorial 5 or 6 questions a day | Python skill tree