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
In questa pagina del sito puoi guardare il video online Part 12 | Python Programming | Creating and working with sets della durata di ore minuti seconda in buona qualità , che l'utente ha caricato oOSylarTechOo 08 gennaio 2023, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 24 volte e gli è piaciuto 1 spettatori. Buona visione!