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-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article focuses on "how to use the built-in general functions of the python container". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor learn how to use the built-in general functions of the python container.

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 = = to manipulate whether the symbol alignment is equal

Len (Container object)

Str (Container object)

Type (Container object) # type supports judging the types of various objects

Let's take a 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 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)) so far I believe you have a deeper understanding of "how to use the built-in general functions of the python container". 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

Development

Wechat

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

12
Report