python中set函数的返回_python回滚Python函数每日一讲 - frozenset集合函数入门及实例...

函数作用

frozenset() 返回一个冻结的集合,冻结后集合不能再添加或删除任何元素。与之对应的是set函数,set无序排序且不重复,是可变的,有add(),remove()等方法。

函数原型frozenset([iterable])

版本兼容性

Python3.x

>= Python2.4

函数参数

iterable -- 可迭代的对象,比如列表、字典、元组、字符串等等。

函数用法

根据参数给定的对象, 返回相应的不可变集合。

W WW.002pc .COM从python回滚Python函数每日一讲 - frozenset集合函数入门及实例分析来看,对python回滚Python函数每日一讲 - frozenset集合函数入门及实例的结果。

返回值

返回新的 frozenset 对象,如果不提供任何参数,默认会生成空集合。

英文解释

Return a new frozenset object, optionally with elements taken from iterable. frozenset is a built-in class. See frozenset and Set Types — set, frozenset for documentation about this class.

For other containers see the built-in set, list, tuple, and dict classes, as well as the collections module.

实例>>> num = frozenset(range(10))     # 创建不可变集合

>>> num

frozenset([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])

>>> sitename = frozenset('pythontab')

>>> sitename

frozenset(['a', 'b', 'h', 'o', 'n', 'p', 't', 'y'])   # 创建不可变集合, 注意:顺序不是按照参数的顺序

>>>

>>> sitename2 = set('pythontab')

>>> sitename2

set(['a', 'b', 'h', 'o', 'n', 'p', 't', 'y']) #可变集合

>>>

>>> sitename2.add('.com') #向可变集合添加成员

>>> sitename2

set(['a', 'b', 'h', 'o', 'n', 'p', 't', 'y', '.com'])

>>>

>>> sitename.add('.com')  #向不可变集合添加成员, 会报错

Traceback (most recent call last):

File "", line 1, in 

AttributeError: 'frozenset' object has no attribute 'add'

>>>

更多:python回滚Python函数每日一讲 - frozenset集合函数入门及实例

https://www.002pc.comhttps://www.002pc.com/python/1179.html

你可能感兴趣的函数,Python,frozenset,一讲,入门,实例

No alive nodes found in your cluster

0踩

0 赞

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值