当前位置:网站首页>TypeError: 'str' object does not support item assignment
TypeError: 'str' object does not support item assignment
2022-07-24 13:59:00 【Blue field soldier】
The following code is used to change the character at a certain position of the string , That's the problem
s = '312141'
s[0] = '0'
python String in with C++ It's a little different ,python The string of is a Immutable object (immutabel object), It means read-only and not write , Thread safety .C++ We can directly use the string of s[0]='0’ This syntax assigns a value to a character in a string , and python Can not be .
stay python in , You can first convert the string into a list , Then assign the value , Then turn it back . Reference resources stackoverflow One of the answers
s = '312141'
t = list(s)
t[0] = '0'
s = ''.join(t)
边栏推荐
- Detailed explanation of switch link aggregation [Huawei ENSP]
- Sringboot plugin framework implements pluggable plug-in services
- Default color setting in uiswitch off state
- 申请了SSL数字证书如何进行域名验证?
- Network security - file upload competitive conditions bypass
- Stack and queue - 225. Implement stack with queue
- Flink高级特性和新特性(八)
- Wechat applet todo case
- 通配符(泛域名)SSL证书
- Mmdrawercontroller gets the current VC for push and pop
猜你喜欢
随机推荐
Mmdrawercontroller gets the current VC for push and pop
Flink容错机制(五)
Solve the problem that the ARR containsobject method returns no every time
Network security - war backdoor deployment
Nmap安全测试工具使用教程
【C语言笔记分享】——动态内存管理malloc、free、calloc、realloc、柔性数组
Default color setting in uiswitch off state
R语言tidyr包的gather函数将从宽表转化为长表(宽表转化为长表)、第一个参数指定原多个数据列名称生成的新数据列名称、第二个参数指定原表内容值、第三个和第四个参数通过列索引指定不变的列名称列表
Flinktable & SQL (VI)
在LNMP架构中搭建Zabbix监控服务
CSP2021 T1 廊桥分配
Sringboot plugin framework implements pluggable plug-in services
The latest and complete Flink series tutorials in 2021_ Preliminary exploration of Flink principle and flow batch integration API (II. V) V2
About the flicker problem caused by using universalimageloader to load pictures and refresh data in recyclerview
软链接、硬链接
【无标题】
JS get object attribute value
One problem encountered:
如何在Ubuntu 18.04和Debian 9上安装PHP 5.6
Ansible服务常用命令模块详细解析








