Robotics & Artificial Intelligence

In Python programming, it is an unordered collection data type that is iterable, mutable and has no duplicate elements. It is represented by { } where the values are enclosed in curly braces.

Read the above paragraph and answer the following questions:

(a) Name the data type that is used in Python.

(b) What will happen, if duplicate elements are present in this data types and executed?

Python Funda

1 Like

Answer

(a) The data type used in Python is Set.

(b) If duplicate elements are present in a set and executed, the set will automatically remove the duplicates and retain only the unique values. This is because a set does not allow duplicate elements. For example, executing My_set = {"red", "blue", "green", "yellow", "blue", "green"} will result in {"red", "blue", "green", "yellow"} being stored, as the duplicate values "blue" and "green" are eliminated.

Answered By

2 Likes


Related Questions