0

String

please help me word='00000' word[5]=str(1) print(word) error: TypeError: 'str' does not support item assignment on line 6

19th Jun 2017, 4:14 PM
Kreez
Kreez - avatar
13 Respostas
+ 6
Yep, strings are immutable in Python. You can't assign anything to it.
19th Jun 2017, 4:22 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
20th Jun 2017, 12:48 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 3
Немножко :)
19th Jun 2017, 4:23 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 3
Никак не работает. Нельзя изменить ни стрингов ни их элементов. В других языках это иногда возможно, но в пайтоне нет.
19th Jun 2017, 4:29 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
0
Да, ты прав( сорян
19th Jun 2017, 4:39 PM
Kreez
Kreez - avatar
0
@Kuba - wouldn't it have been easier/better to stick to English, so that more people can benefit from the discussion??? @Kreez - you can append to a string like this: word+=str(1) Or you can replace a letter by creating a new string entirely: word=word[:2]+str(1)+word[3:]
20th Jun 2017, 7:44 AM
Bogdan Sass
Bogdan Sass - avatar
0
thank you
20th Jun 2017, 7:46 AM
Kreez
Kreez - avatar
0
Can you guys answer one more question?
20th Jun 2017, 12:07 PM
Kreez
Kreez - avatar
0
I wrote the program, but she gave an error word=('00000') print(word) bit={ } bit[0]=word i=0 while 32: i+=1 #The start of block d=4 n=word[:d]+'1' bit[i]=n #The end of block print(bit) error: 00000 Traceback (most recent call last): File "source_file.py", line 13, in <module> bit[i]=n #The end of block MemoryError
20th Jun 2017, 12:10 PM
Kreez
Kreez - avatar
- 1
ты ведь русский ну или русский понимаешь?
19th Jun 2017, 4:23 PM
Kreez
Kreez - avatar
- 1
они изменяются
19th Jun 2017, 4:24 PM
Kreez
Kreez - avatar
- 1
вот так работает: word='00000' word[5]=('1') print(word) попробуй
19th Jun 2017, 4:25 PM
Kreez
Kreez - avatar
- 1
стоп теперь не работает
19th Jun 2017, 4:27 PM
Kreez
Kreez - avatar