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 the built-in general functions of the python container

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces "how to use the built-in general functions of the python container". In the daily operation, I believe many people have doubts about how to use the built-in general functions of the python container. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "how to use the built-in general functions of the python container". Next, please follow the editor to study!

What are the common operations that are easy to use with this data?

In addition to the addition, deletion, query and modification of data (in addition to the immutable length of tuple and immutable elements), we also need the following operations:

Compare and compare operation

Calculate the number of elements

Print out the container

Get container type

Use the = = operation symbol to compare whether it is equal or not. Len (container object) str (container object) type (container object) # type supports judging the types of various objects. Let's look at the code of several containers.

Strictly speaking, we do not use the tuple tuple type as a data container.

We use it more to describe fixed-length structures.

#! / usr/bin/env python#-*-coding: utf-8-*-# @ Time: 12:40 on 2021-11-8 # @ Author: LeiXueWei# @ CSDN/Juejin/Wechat: Ray academic Committee # @ XueWeiTag: CodingDemo# @ File: _ _ init__.py.py# @ Project: hellotuple1 = ("name", "leixuewei") tuple2 = ("name", "leixuewei") print ("len:", len (tuple1) print ("= =:" Tuple1 = = tuple2) print ("dict1:", str (tuple1)) print ("type:", type (tuple1))

The running effect is as follows:

Here is the same operation for list:

#! / usr/bin/env python#-*-coding: utf-8-*-# @ Time: 12:40 on 2021-11-8 # @ Author: LeiXueWei# @ CSDN/Juejin/Wechat: Ray academic Committee # @ XueWeiTag: CodingDemo# @ File: commonlistops.py# @ Project: hellolist1 = ["name", "leixuewei"] list2 = ["name", "leixuewei"] print ("len:", len (list1) print ("=:", list1 = = list2) print ("list1:" Str (list1)) print ("type:", type (list1))

The running effect is as follows:

The following is the operation of the dict dictionary type:

#! / usr/bin/env python#-*-coding: utf-8-*-# @ Time: 12:40 on 2021-11-8 # @ Author: LeiXueWei# @ CSDN/Juejin/Wechat: Ray academic Committee # @ XueWeiTag: CodingDemo# @ File: _ _ init__.py.py# @ Project: hellodict1 = {"name": "leixuewei"} dict2 = {"name": "leixuewei"} print ("len:", len (dict1) print ("= =:" Dict1 = = dict2) print ("dict1:", str (dict1)) print ("type:", type (dict1))

The running effect is as follows:

At this point, the study on "how to use the built-in general functions of the python container" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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

Development

Wechat

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

12
Report