Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What are the little-known features of python

Shulou Source: shulou.com Published: 2022-06-01 00:58:12 10月02日 Update

This article focuses on "what are the little-known features of python". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn what are the little-known features of python.

Subtle string > a = "wtf"

> b = "wtf"

> an is b

True

> a = "wtf!"

> b = "wtf!"

> an is b

False

> A, b = "wtf!", "wtf!"

> an is b

The result returned by True # 3.7is False. Unexpected "is" > a = 256

> b = 256

> an is b

True

> a = 257

> b = 257

> an is b

False

A = 257; b = 257

> an is b

True said that the tuple is immutable. Some_tuple = ("A", "tuple", "with", "values")

Another_tuple = ([1,2], [3,4], [5,6])

> some_tuple [2] = "change this"

TypeError: 'tuple' object does not support item assignment

> another_tuple [2] .append (1000) # No error occurs here

> another_tuple

([1,2], [3,4], [5, 6, 1000])

> another_tuple [2] + = [99999]

TypeError: 'tuple' object does not support item assignment

> another_tuple

([1, 2], [3, 4], [5, 6, 1000, 9999]) vanishing global variable e = 7

Try:

Raise Exception ()

Except Exception as e:

Pass

Output

> > print (e)

NameError: which value def some_func () is returned when name 'e'is not definedtry encounters finally:

Try:

Return 'from_try'

Finally:

Return 'from_finally'

Output

> > some_func ()

From_finally' at this point, I believe you have a deeper understanding of "what are the little-known features of python?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Functions features little-known content learning output practical subtle deeper unexpected global interest variables characters strings practicality practicality simple operation methods more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Huawei NVidia MariaDB Shulou Information