Like many other popular programming languages, strings in Python are arrays of bytes representing unicode characters.
However, Python does not have a character data type, a single character is simply a string with a length of 1.
Square brackets can be used to access elements of the string.
Example
Get the character at position 1 (remember that the first character has the position 0):
a = "Hello, World!"
print(a[1])
>>> e
Since strings are arrays, we can loop through the characters in a string, with a for loop.(str이 array니까!)
Example
Loop through the letters in the word "banana":
for x in "banana":
print(x)
>>> b, a, n,,,, 순차적으로 하나씩 출력됨
__iter__
객체가 있는지 확인하면 됨!# list, dcitionary, str는 당연 반복가능!
[].__iter__()
>>> <list_iterator at 0x7f10d1894490>
{'a': 1}.__iter__()
>>> <dict_keyiterator at 0x7f10d18d2410>
'1'.__iter__()
>>> <str_iterator at 0x7f10e0135250>
# 하지만 int는 안되는 것을 확인할 수 있다.
int(1).__iter__()
>>> AttributeError: 'int' object has no attribute '__iter__'