Set
A set is an unordered collection of unique elements. It is a data type that allows storing multiple values but automatically eliminates duplicates.
For example, let’s say you have a set of animal stickers. You have a lion, a monkey, and a giraffe in this set. But you don’t have two lions or two monkeys, because sets only keep one of each thing.
Python3
# Let's create a set of your favourite fruits favorite_fruits = { "apple" , "banana" , "orange" } # Now, let's print the set print (favorite_fruits) # Adding a new fruit to the set favorite_fruits.add( "grapes" ) print (favorite_fruits) # Trying to add a duplicate fruit (banana) favorite_fruits.add( "banana" ) # This won't be added because sets only keep unique items print (favorite_fruits) # Removing a fruit from the set favorite_fruits.remove( "apple" ) print (favorite_fruits) # Checking if the fruit is in the set print ( "banana" in favorite_fruits) # This will print True # Checking the number of fruits in the set print ( len (favorite_fruits)) # This will print the total number of fruits in the set |
Output:
{"apple", "banana", "orange"} {"apple", "banana", "orange", "grapes"} {"apple", "banana", "orange", "grapes"} {"banana", "orange", "grapes"} true 3
Python for Kids – Fun Tutorial to Learn Python Programming
Python for Kids – Python is an easy-to-understand and good-to-start programming language. In this Python tutorial for kids or beginners, you will learn Python and know why it is a perfect fit for kids to start. Whether the child is interested in building simple games, creating art, or solving puzzles, Python provides the foundation to the kids or any beginner for their coding journey.
Programming is an essential skill in today’s world because programming is used everywhere in our surroundings. And to learn programming, we have to learn a programming language and Python is the best to start with programming language. It has a simple syntax and readability is the best choice for kids to understand programming concepts. In this Python tutorial, you’ll learn all the basic concepts, installation processes, and fundamental programming concepts.
Contact Us