Answer the question
In order to leave comments, you need to log in
Why does for i in work with a set like for in in range?
# создаем множество
a = set('123')
# получаем доступ к элементам
for i in a: print(i)
>>> {1, 2, 3}
>>> {1, 2, 3}
>>> {1, 2, 3}
a = set(1, 2, 3)
>>> Error
a = set('1,2,3')
>>> {'1', '2', '3'}
Answer the question
In order to leave comments, you need to log in
'123' is a string. A string is a sequence of characters. Therefore, a string can be turned into any other sequence, it can be sorted character by character, it can be overtaken into a list character by character.
But with the transfer of the string to the set () set, there will be a bummer: you will get one instance of each character from the string :)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question