当前位置:网站首页>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)
边栏推荐
- OWASP ZAP安全测试工具使用教程(高级)
- SQL Server 启停作业脚本
- R language uses the sum function of epidisplay package to calculate the descriptive statistical summary information of the specified variables in dataframe under different grouping variables, visualiz
- JS get object attribute value
- Matlab program for natural gas flow calculation
- 三层交换机配置MSTP协议详解【华为eNSP实验】
- RHCE first operation
- Get (min / max value) of (object array / array)
- 5年接触近百位老板,身为猎头的我,发现升职的秘密不过4个字
- R language uses the statstack function of epidisplay package to view the statistics (mean, median, etc.) of continuous variables and the corresponding hypothesis test in a hierarchical manner based on
猜你喜欢

网络安全——使用Evil Maid物理访问安全漏洞进行渗透

Solve the problem that the ARR containsobject method returns no every time

After five years of contact with nearly 100 bosses, as a headhunter, I found that the secret of promotion was only four words

Chapter VI bus

Rhcsa sixth note

Error importing header file to PCH

CSDN垃圾的没有底线!

JS execution mechanism

2022.7.22 simulation match

CSDN garbage has no bottom line!
随机推荐
Flink综合案例(九)
Editor formula
Detailed explanation of MSTP protocol for layer 3 switch configuration [Huawei ENSP experiment]
代码签名证书与SSL证书区别
【C语言笔记分享】——动态内存管理malloc、free、calloc、realloc、柔性数组
CAS atomic type
数据湖系列文章
Summary of week 22-07-23
Flink fault tolerance mechanism (V)
About the flicker problem caused by using universalimageloader to load pictures and refresh data in recyclerview
Packet switching and label switching in MPLS
CSDN garbage has no bottom line!
String - 459. Repeated substrings
Ansible服务常用命令模块详细解析
OWASP ZAP安全测试工具使用教程(高级)
The R language uses the DOTPLOT function of epidisplay package to visualize the frequency of data points in different intervals in the form of point graphs, uses the by parameter to specify the groupi
Solve the problem that the ARR containsobject method returns no every time
JQ remove an element style
2022.7.22 模拟赛
Flink advanced features and new features (VIII)