+ 3

When we define a string, do we cosider it as a list even we don't put it's mark?

for example: str="Hello world!" we don't put it in [ ]

20th Apr 2017, 6:59 PM
Fatemah Abd El-Aziz
Fatemah Abd El-Aziz - avatar
1 Odpowiedź
+ 6
Yes, strings are essentially "lists", in a sense, and can be considered as such in understanding - at least to some extent. Lists can be iterated upon, indexed, added, multiplied, sliced and so on. However, there are substantial differences, mainly in handling them. Unlike lists, strings are not pointer-dependent types. For lists you have: a = [1, 2, 3] b = a a[0] = 0 print (b) >>> [0, 2, 3] Strings do not follow any of that pattern. Of course, you can't assign anything to a string element, as they are immutable (again, unlike lists).
20th Apr 2017, 7:44 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar