A collection is an unordered collection of different elements. Unlike sequence types (such as lists, strings, etc.), collections do not have slicing operations.
Python collections are divided into two types: (Recommended learning: Python video tutorial)
set - a mutable collection, elements in the collection can be dynamically added or deleted.
frozenset - Immutable collection, the elements in the collection cannot be changed.
Note: The return value of union, intersection, difference, etc. has the same type as the leftmost operand. For example: s & t take the intersection. If the s collection is a set type collection and the t collection is a frozenset type collection, the returned result will be a set type collection.
rozenset() function
Description: You can convert other combined data types into immutable collection types (or convert mutable collection type set into immutable The collection type frozenset) returns an immutable collection with no duplicate elements and an arbitrary order.
Syntax:
frozenset() -> empty frozenset object 返回一个不可变空集合 frozenset(iterable) -> frozenset object 返回一个不可变新集合
iterable - the combined data type to be converted.
Program example:
s1 = frozenset() #创建一个不可变的空集合。 l = [1.23,"a"] #列表类型 d = {1:"a",2:"b"} #字典类型 a = (1,2,"b") #元组类型 s = "厉害了,我的国" #字符串 c = set("1,2,3a") #可变集合 #将列表,字典,元组,字符串 可变集合 转化为不可变集合 s2 = frozenset(s) s3 = frozenset(l) s4 = frozenset(d) s5 = frozenset(a) s6 = frozenset(c) #将可变集合转换为不可变集合s6 print(s1) print(s2) print(s3) print(s4) print(s5) print(s6)
For more Python-related technical articles, please visit the Python Tutorial column to learn!
The above is the detailed content of Are collections mutable in python?. For more information, please follow other related articles on the PHP Chinese website!

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于Seaborn的相关问题,包括了数据可视化处理的散点图、折线图、条形图等等内容,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于进程池与进程锁的相关问题,包括进程池的创建模块,进程池函数等等内容,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于简历筛选的相关问题,包括了定义 ReadDoc 类用以读取 word 文件以及定义 search_word 函数用以筛选的相关内容,下面一起来看一下,希望对大家有帮助。

VS Code的确是一款非常热门、有强大用户基础的一款开发工具。本文给大家介绍一下10款高效、好用的插件,能够让原本单薄的VS Code如虎添翼,开发效率顿时提升到一个新的阶段。

pythn的中文意思是巨蟒、蟒蛇。1989年圣诞节期间,Guido van Rossum在家闲的没事干,为了跟朋友庆祝圣诞节,决定发明一种全新的脚本语言。他很喜欢一个肥皂剧叫Monty Python,所以便把这门语言叫做python。

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于数据类型之字符串、数字的相关问题,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于numpy模块的相关问题,Numpy是Numerical Python extensions的缩写,字面意思是Python数值计算扩展,下面一起来看一下,希望对大家有帮助。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download
The most popular open source editor

Dreamweaver Mac version
Visual web development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
