日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

Python frozenset 集合 - Python零基础入门教程

發(fā)布時間:2024/9/27 python 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python frozenset 集合 - Python零基础入门教程 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

目錄

  • 一.Python frozenset 集合語法
  • 二.Python frozenset 集合使用
  • 三.猜你喜歡

零基礎(chǔ) Python 學(xué)習(xí)路線推薦 : Python 學(xué)習(xí)目錄 >> Python 基礎(chǔ)入門

在前一篇文章中我們對 Python set 集合 做了詳細的講解,而本文講解的 frozenset 集合 其實和 set 集合類似!

與 Python set 集合區(qū)別在于 frozenset 集合不能修改/添加/刪除,其他功能和 set 集合一樣,這就有點類似列表 list 和元組 tuple 的區(qū)別。

一.Python frozenset 集合語法

# 創(chuàng)建一個frozenset集合 a = frozenset(iterable)

** 其中 iterable 是序列或者可迭代對象,并返回 frozenset 集合**;

二.Python frozenset 集合使用

# !usr/bin/env python # -*- coding:utf-8 _*- """ @Author:猿說編程 @Blog(個人博客地址): www.codersrc.com @File:Python frozenset 集合.py @Time:2021/04/04 11:00 @Motto:不積跬步無以至千里,不積小流無以成江海,程序人生的精彩需要堅持不懈地積累!"""a = frozenset(["q123","python","frozenset"]) print(a) # 獲取a的類型 print(type(a)) # 修改frozenset集合數(shù)據(jù),程序報錯:AttributeError: 'frozenset' object has no attribute 'add' # a.add("hello")''' 輸出結(jié)果:frozenset({'frozenset', 'python', 'q123'}) <class 'frozenset'> '''

在上面代碼中,如果嘗試修改 frozenset 集合的數(shù)據(jù),即使用 add 添加數(shù)據(jù),程序報錯:AttributeError: ‘frozenset’ object has no attribute ‘a(chǎn)dd’!

原因:frozenset 集合不能修改/添加/刪除,其他功能和 set 集合一樣

三.猜你喜歡

  • Python 字符串/列表/元組/字典之間的相互轉(zhuǎn)換
  • Python 局部變量和全局變量
  • Python type 函數(shù)和 isinstance 函數(shù)區(qū)別
  • Python is 和 == 區(qū)別
  • Python 可變數(shù)據(jù)類型和不可變數(shù)據(jù)類型
  • Python 淺拷貝和深拷貝
  • Python 遞歸函數(shù)
  • Python sys 模塊
  • Python 列表 list
  • Python 元組 tuple
  • Python 字典 dict
  • Python 條件推導(dǎo)式
  • Python 列表推導(dǎo)式
  • Python 字典推導(dǎo)式
  • Python 函數(shù)聲明和調(diào)用
  • Python 不定長參數(shù) *argc/**kargcs
  • 未經(jīng)允許不得轉(zhuǎn)載:猿說編程 ? Python frozenset 集合

    總結(jié)

    以上是生活随笔為你收集整理的Python frozenset 集合 - Python零基础入门教程的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。