关于#python#的问题,请各位专家解答!

img


这哪里不对啊 有没有会的来给我看一下
(上课闲的没事写在本子上的代码 这列表我看老长时间了)

通过参考网络搜索的资料,发现字符串的format()方法的使用有点错误。

修改如下:

参考链接:


python格式化输出之format用法 - 知乎 format用法:format()功能很强大,它把字符串当成一个模板,通过传入的参数进行格式化,并且使用大括号‘{}’作为特殊字符代替‘%’。 使用方法由两种:b.format(a)和format(a,b)。 1、基本用法 (1)不带编号,即… https://zhuanlan.zhihu.com/p/151442933

Python中的format方法 - 知乎 内置的 format() 函数和 str.format() 方法把各个类型的格式化方式委托给相应的 .__format__(format_spec) 方法。format_spec是格式说明符,它是:format(my_obj, 格式说明符) 的第二个参数,或者str.format() 方… https://zhuanlan.zhihu.com/p/424862897


person=['zhangsan','lisi','noboday']
person.append('wangwu')
print(person)

# https://www.runoob.com/python/att-string-format.html
# https://zhuanlan.zhihu.com/p/151442933
# https://zhuanlan.zhihu.com/p/424862897
a= "My best friend is {}.".format(person[3].title())
print(a)

person[0]='zhaoliu'
person[1]='dingqi'
del person[2]
person[2]='huba'
person.append('xuejiu')
person.append('yuanshi')
b="My best friend is {}.".format(person[2])
print(person)
print(b)


img

第一个问题:将format改为f
第二个问题:所有的标点符号都要在英文状态下输入。
如果觉得有用,请采纳一下,非常感谢!