| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [View Raw Code] [Original HTTPS Page] |
Synatx:
setname={element}
setname1=set(elements)Example: You can not create a blank set like this
blankset={}
print(type(blankset)) Output:
<class 'dict'>
Create blank Set using built in function
myset=set()
print(type(myset))Output:
<class 'set'>
Create a set with 1,2,3,4 elements
myset={1,2,3,4}
print(myset)Output:
{1,2,3,4}
my_set = {1, 2, [3, 4]}Output:
TypeError: unhashable type: 'list'
myset={1,2,3,4}
for i in myset:
print(i)Output
1 2 3 4
Example:
color={'red','green','blue'}
if('red' in color):
print('red is present')
else:
print('red is not found')Output:
red is present
Example
color={'red','green','blue'}
length=len(color)
print(length) Output:
3
| Back | FazBrowse Home | New Git URL |