Python Set update() 方法

Python 3 教程 · 2019-02-06 21:42:22

描述

update() 方法用于修改当前集合,可以添加新的元素或集合到当前集合中,如果添加的元素在集合中已存在,则该元素只会出现一次,重复的会忽略。

语法

update() 方法语法:

set.update(set)

参数

  • set -- 必需,可以是元素或集合
  • 返回值

    无。

    实例

    合并两个集合,重复元素只会出现一次:

    实例 1

    x = {"apple", "banana", "cherry"} y = {"google", "codercto", "apple"} x.update(y) print(x)

    输出结果为:

    {'banana', 'apple', 'google', 'codercto', 'cherry'}
    

点击查看所有 Python 3 教程 文章: https://codercto.com/courses/l/10.html

查看所有标签

Data Structures and Algorithms in Python

Data Structures and Algorithms in Python

Michael T. Goodrich、Roberto Tamassia、Michael H. Goldwasser / John Wiley & Sons / 2013-7-5 / GBP 121.23

Based on the authors' market leading data structures books in Java and C++, this book offers a comprehensive, definitive introduction to data structures in Python by authoritative authors. Data Struct......一起来看看 《Data Structures and Algorithms in Python》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

html转js在线工具
html转js在线工具

html转js在线工具