Python Set update() MethodPython Functions

Difficulty Level:
Difficulty Level:

The update() method adds elements from a set to another set.

Example

#!/usr/bin/python3
# -*- coding: UTF-8 -*-

A = {1,2,3,4}
B = {1,4,5,6}
C = {1,11}

A.update(B)
B.update(C)

print("The  set A  is",A)

print("The  set B  is",B)

Output:

The  set A  is {1, 2, 3, 4, 5, 6}
The  set B  is {1, 4, 5, 6, 11}

Syntax

set_x.update()(set_y)

Parameters

The method doesn’t take any parameters.

Return Value

It returns a new set.

Advertisement

© 2021 Pythonexample.org, all rights reserved. Privacy Policy | Contact Us