Get the App
SLTechnology News&Howtos  ›  Development  › 

How python uses the Walrus operator

Shulou Source: shulou.com Published: 2022-06-01 05:26:46 10月04日 Update

This article mainly shows you "how to use the walrus operator in python". It is easy to understand and well organized. I hope it can help you solve your doubts. Let me lead you to study and learn the article "how to use the walrus operator in python".

Walrus operator

The walrus operator (: =) is a new feature in Python version 3.8. It is just another name for the assignment expression (which assigns values to variables in the expression).

In general, when an expression uses a variable, the variable declaration must be in advance. Using the walrus operator, a variable assignment can be included in an expression and can be used immediately.

> a = ['jacks,' asides, 'kings],' c'] > > if (n: = len (a))% 2 = = 1:. Print (f'The number of letters is {n}, which is odd.')... The number of letters is 5, which is odd. These are all the contents of the article "how python uses Walrus operators". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Walrus operator operation variable expression content article learning help name new feature easy to understand more organization version knowledge tape industry information information channel Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS vpn Huawei Microsoft Linux