Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

difference between set and tuple in python

Lists and tuples are standard Python data types that store values in a sequence. Sets are another standard Python data type that also store values. The major difference is that sets, unlike lists or tuples, cannot have multiple occurrences of the same element and store unordered values.
Comment

Set Vs Tuple In Python

myset = {"bananas", "apples", "cherries"}
mytuple = ("bananas", "apples", "cherries")
print(myset)
#outputs {'apples', 'cherries', 'bananas'}
print(mytuple)
#outputs ('bananas', 'apples', 'cherries')

myset = {2, 1, 3}
mytuple = (2, 1, 3)
print(myset)
#outputs {1,  2,  3}
print(mytuple)
#outputs (2, 1, 3)

Comment

tuple vs set python

tuple = (1,2,3,4,5,6,7,8,9, 1,2,3) # output: (1,2,3,4,5,6,7,8,9, 1,2,3) will be same
set = (1,2,3,4,5,6,7,8,9, 1,2,3) # output: (1,2,3,4,5,6,7,8,9) // removes the duplicate values
Comment

PREVIOUS NEXT
Code Example
Python :: is the multiply code in python 
Python :: how to create list in python 
Python :: gaussian 
Python :: add to list in python 
Python :: python convert time 
Python :: python print array 
Python :: turn numpy function into tensorflow 
Python :: how to read an xml file 
Python :: python 3.8 release date 
Python :: Example 1: Reset Index & Drop Old Index pandas 
Python :: split dataframe row on delimiter python 
Python :: how to make a variable in python 
Python :: turn list into string 
Python :: python generators with for 
Python :: what is thread in python 
Python :: python 3 string length 
Python :: Showing all column names and indexes dataframe python 
Python :: pandas group by to dataframe 
Python :: brownie transaction info 
Python :: add variable to print python 
Python :: WARNING: Ignoring invalid distribution -ip (c:python310libsite-packages) 
Python :: landscape odoo report 
Python :: how to make a window in python ursina 
Python :: run persistent py script in background (good for flask) 
Python :: how to deploy to shinyapps.io 
Python :: index operator in python without input 
Python :: xmgrace conditions 
Python :: How to know position on Kivy 
Python :: pandas dtodays date csv 
Python :: How to count number of distinct elements in specified axis 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =