Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the built-in general functions of the python container

Shulou Source: shulou.com Published: 2022-06-02 06:25:08 10月19日 Update

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!

Tags: Container function object type learning effect data more utf-8 run element variable help utility next no code dictionary quantity article Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Linux OPPO Reno Docker Apple