How To Add Integer Input In A Set Object
unable to add an item into a set taking it as an input from user input>>j=set() input>>j.add(int(input())) 4 TypeError: descriptor 'add' requires a 'set' object but re
Solution 1:
2 ways to do it:
j = set()
j.add(a)
# a can be anything. If you want integer you can type cast it with int()j = {''}
# initializing a set in this way requires some default parameter otherwise python will make it a dictionaryj.add(1)
orj.add(a)
# where a is an integerj.remove('')
# remove the initial string that we added
Solution 2:
It because you have to call it to get a set
j = set()
j.add(int(input()))
Post a Comment for "How To Add Integer Input In A Set Object"