Course Content

Python Data Structures

## Python Data Structures

# Creating a Set

In Python, there are several ways to create sets.

- You can use the built-in
`set()`

function and pass the desired elements to it; - You can place a sequence of elements inside curly braces and separate them with commas.

Here are some key points about sets:

- They are mutable;
- Sets only contain unique elements. If you add duplicate elements when creating a set, they'll be removed in the final set;
- The order of elements in a set is not guaranteed;
- Set elements can be of various data types.

Let's dive into an example. First, we'll create a set using the `set()`

function.

Next, we'll create sets using curly braces.

Task

Follow these steps:

- Make a set with strings as follows:
`'pineapple'`

,`'pear'`

,`'cherry'`

; - Construct a set with a mix of data types like this:
`'pear'`

,`45`

,`None`

,`'car'`

,`'Joe'`

,`12`

,`5`

.

Note

Please write values in the exact order given in the task instructions.

Task

Follow these steps:

- Make a set with strings as follows:
`'pineapple'`

,`'pear'`

,`'cherry'`

; - Construct a set with a mix of data types like this:
`'pear'`

,`45`

,`None`

,`'car'`

,`'Joe'`

,`12`

,`5`

.

Note

Please write values in the exact order given in the task instructions.

Everything was clear?

# Creating a Set

In Python, there are several ways to create sets.

- You can use the built-in
`set()`

function and pass the desired elements to it; - You can place a sequence of elements inside curly braces and separate them with commas.

Here are some key points about sets:

- They are mutable;
- Sets only contain unique elements. If you add duplicate elements when creating a set, they'll be removed in the final set;
- The order of elements in a set is not guaranteed;
- Set elements can be of various data types.

Let's dive into an example. First, we'll create a set using the `set()`

function.

Next, we'll create sets using curly braces.

Task

Follow these steps:

- Make a set with strings as follows:
`'pineapple'`

,`'pear'`

,`'cherry'`

; - Construct a set with a mix of data types like this:
`'pear'`

,`45`

,`None`

,`'car'`

,`'Joe'`

,`12`

,`5`

.

Note

Please write values in the exact order given in the task instructions.

Task

Follow these steps:

- Make a set with strings as follows:
`'pineapple'`

,`'pear'`

,`'cherry'`

; - Construct a set with a mix of data types like this:
`'pear'`

,`45`

,`None`

,`'car'`

,`'Joe'`

,`12`

,`5`

.

Note

Please write values in the exact order given in the task instructions.

Everything was clear?

# Creating a Set

In Python, there are several ways to create sets.

- You can use the built-in
`set()`

function and pass the desired elements to it; - You can place a sequence of elements inside curly braces and separate them with commas.

Here are some key points about sets:

- They are mutable;
- Sets only contain unique elements. If you add duplicate elements when creating a set, they'll be removed in the final set;
- The order of elements in a set is not guaranteed;
- Set elements can be of various data types.

Let's dive into an example. First, we'll create a set using the `set()`

function.

Next, we'll create sets using curly braces.

Task

Follow these steps:

- Make a set with strings as follows:
`'pineapple'`

,`'pear'`

,`'cherry'`

; - Construct a set with a mix of data types like this:
`'pear'`

,`45`

,`None`

,`'car'`

,`'Joe'`

,`12`

,`5`

.

Note

Please write values in the exact order given in the task instructions.

Task

Follow these steps:

- Make a set with strings as follows:
`'pineapple'`

,`'pear'`

,`'cherry'`

; - Construct a set with a mix of data types like this:
`'pear'`

,`45`

,`None`

,`'car'`

,`'Joe'`

,`12`

,`5`

.

Note

Please write values in the exact order given in the task instructions.

Everything was clear?

In Python, there are several ways to create sets.

- You can use the built-in
`set()`

function and pass the desired elements to it; - You can place a sequence of elements inside curly braces and separate them with commas.

Here are some key points about sets:

- They are mutable;
- The order of elements in a set is not guaranteed;
- Set elements can be of various data types.

Let's dive into an example. First, we'll create a set using the `set()`

function.

Next, we'll create sets using curly braces.

Task

Follow these steps:

- Make a set with strings as follows:
`'pineapple'`

,`'pear'`

,`'cherry'`

; - Construct a set with a mix of data types like this:
`'pear'`

,`45`

,`None`

,`'car'`

,`'Joe'`

,`12`

,`5`

.

Note

Please write values in the exact order given in the task instructions.