
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Check if one tuple is subset of other in Python
When it is required to check if one tuple is a subset of the other, the 'issubset' method is used.
The 'issubset' method returns True if all the elements of the set are present in another set, wherein the other set would be passed as an argument to the method.
Otherwise, this method returns False.
Below is a demonstration of the same −
Example
my_tuple_1 = (87, 90, 31, 85) my_tuple_2 = (34, 56, 12, 5) print("The first tuple is :") print(my_tuple_1) print("The second tuple is :") print(my_tuple_2) my_result = set(my_tuple_2).issubset(my_tuple_1) print("Is the second tuple a subset of the first tuple ? ") print(my_result)
Output
The first tuple is : (87, 90, 31, 85) The second tuple is : (34, 56, 12, 5) Is the second tuple a subset of the first tuple ? False
Explanation
- Two tuples are defined, and are displayed on the console.
- The issubset method is used by passing first tuple to it, and comparing it with the second tuple.
- This result is assigned to a value.
- It is displayed as output on the console.
- Related Articles
- Check if one list is subset of other in Python
- Check if variable is tuple in Python
- Check if one of the numbers is one’s complement of the other in Python
- Check if element is present in tuple in Python
- Check if element is present in tuple of tuples in Python
- Check if bitwise AND of any subset is power of two in Python
- Check One Array is Subset of Another Array in Java
- Python – Check if any list element is present in Tuple
- Python Program to check if the tuple is empty
- Check if characters of one string can be swapped to form other in Python
- Check if tuple has any None value in Python
- Check if tuple and list are identical in Python
- Check if max occurring character of one string appears same no. of times in other in Python
- Program to check whether one tree is subtree of other or not in Python
- Program to find length of the largest subset where one element in every pair is divisible by other in Python

Advertisements