Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python Set issubset() Method

Python Set issubset() Method

Python3 Lists Python Sets


Description

The issubset() method determines whether all elements of a set are contained in a specified set, returning True if so and False otherwise.

Syntax

Syntax of the issubset() method:



set.issubset(set)

Parameters

Return Value

Returns a Boolean; True if all are contained, otherwise False.

Example

Determine whether all elements of set x are contained in set y:

Example 1

x

= {

"

a

"

,

"

b

"

,

"

c

"

}

y

= {

"

f

"

,

"

e

"

,

"

d

"

,

"

c

"

,

"

b

"

,

"

a

"

}

z

=

x

.

issubset

(

y

)

print

(

z

)

The output is:



True

Returns False if not all are contained:

Example 1

x

= {

"

a

"

,

"

b

"

,

"

c

"

}

y

= {

"

f

"

,

"

e

"

,

"

d

"

,

"

c

"

,

"

b

"

}

z

=

x

.

issubset

(

y

)

print

(

z

)

The output is:



False

Python3 Lists Python Sets