python - Python replace method
问题描述
I write the code below but replace method is not working.
code:
courses = input("Please enter the courses you have taken previously with letter grades: ")
courses.replace("M","X")
print(courses)
Please enter the courses you have taken previously with letter grades:
MATH101:A;SPS101:B;CS201:B+;HIST191:D;CS204:F;CS210:S:
MATH101:A;SPS101:B;CS201:B+;HIST191:D;CS204:F;CS210:S:
解决方案
replace 不会在原地改变字符串。str.replace()
courses = courses.replace("M", "X")
推荐阅读
- reactjs - 当输入不聚焦时使输入标签保持不变
- linux - 进程退出后内存仍在使用
- c++ - 为什么我在进行单元测试时 Visual Studio 会给出未解决的外部符号错误?
- mysql - MySQL UNION ALL 多重使用优化
- rest - 使用不同的 WebAPI 将相关数据输入数据库
- c# - 定义不需要访问器的数据类型(单属性类)
- python - 带或不带括号的对象属性标注信息
- python - 如何对字符串中的所有字符(包括安全字符)进行 urlencode?
- python - 如何让我的下一个 elif 语句打印?
- amazon-web-services - aws.events 的 EventBridge 规则问题