Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use web mutable and immutable data types

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article focuses on "how to use web mutable and immutable data types". 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 how to use web mutable and immutable data types.

Immutable data type

Numeric number (including int, float, bool, complex), string string, tuple tuple.

Under the same code block, if the values of different variables are the same and are immutable data types, then their id is also the same. In fact, they are all references to the same value, which not only saves memory but also improves running efficiency. For example:

Num1=1000num2=1000print (id (num1), id (num2)) out:2321267850064 2321267850064

It is important to note that the output is inconsistent in the REPL interactive environment because each line of code is a separate block of code in the REPL interactive environment.

> > num1=1000 > > num2=1000 > > print (id (num1), id (num2)) 2404872583088 2404872583472 variable data type

List list, dictionary dict, collection set.

If the values of different variables are the same and are of variable data types, then their id must be different, and they cannot be references to the same value.

For example:

> List1= > List2= [1pje 2dag3] > print (id (List1), id (List2)) 2311885997568 2311885997696 > print (List1==List2) True so far, I believe you have a deeper understanding of "how to use web variable data types and immutable data types". 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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report