Part 12 | Python Programming | Creating and working with sets

Veröffentlicht am: 08 Januar 2023
auf dem Kanal: oOSylarTechOo
24
1

This is part 12 of a series of python coding I am having fun with and want to show others interested or stuck.

Code Example:

#Creating and Working with sets
#Finding the number of items in a set
#Add and delete items using the add(), remove(), & update() method

#Create the sets
fruit_set = {"apple", "banana", "cherry"}
tropical_set = {"pineapple", "mango", "papaya"}

#print the number of items in the fruit_set
print(fruit_set)
print(len(fruit_set))

#add items to the set by using the .add() method
fruit_set.add("orange")

print(fruit_set)
print(len(fruit_set))

#Add items from two sets together using the update() method
fruit_set.update(tropical_set)

print(fruit_set)
print(len(fruit_set))

#Say you accidentally added a non-fruit item to the set
fruit_set.add('pen')
print(fruit_set)

#You can remove the item from the fruit set by using the
#.remove() method
fruit_set.remove('pen')
print(fruit_set)

#python #pythonprogramming #pythontutorial #pythonforbeginners #shortsfeed
Music: Paid Subscription with Wondershare Filmora


Auf dieser Seite können Sie das Online-Video Part 12 | Python Programming | Creating and working with sets mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer oOSylarTechOo 08 Januar 2023 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 24 Mal angesehen und es wurde von 1 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!