为什么“大写”在终端中不起作用
这是代码
mysk = ["python 50%", "c++ 20%", "html 0%", "js 0%"]
myskwithcounter = enumerate(mysk, 1)
for c, s in myskwithcounter :
print(f"{c}) {s}".capitalize())
这就是结果。
1) python 50%
2) c++ 20%
3) html 0%
4) js 0%
PS G:test>
回答
capitalize()将字符串的第一个字符更改为大写。第一个字符是来自c变量的数字,而不是来自 的字符串s。
调用s.capitalize()以大写语言。
print(f"{c}) {s.capitalize()}")