注意,根据2018版本二级python考试要求,考试环境为Windows7 & python3.5 & python自带IDLE

参考答案:

我的解法:
# 请在______处使用一行代码或表达式替换
# 注意:请不要修改其他已给出代码
s = input("请输入一个字符串:")
print("{0:*^30}".format(s))
其中核心是理解format的用法
在Python 简明教程的format 方法讲解有举例
核心是理解
a=5
b=6
c=7
print('first is {1} ,second is {0} ,third is {2}'.format(a,b,c))
print('first is {0} ,second is {1} ,third is {2}'.format(a,b,c))
'''
输出
first is 6 ,second is 5 ,third is 7
first is 5 ,second is 6 ,third is 7
'''
上面是为了理解print({0:*^30}.format(s))
中0与s的对应关系
a='hello'
b='world'
c='$$$'
print("{0:*^30}".format(a,b,c))
print("{2:*^30}".format(a,b,c))
print("{1:!^30}".format(a,b,c))
print("{2:^^30}".format(a,b,c))
print("{2:^^10}".format(a,b,c))
'''
输出
************hello*************
*************$$$**************
!!!!!!!!!!!!world!!!!!!!!!!!!!
^^^^^^^^^^^^^$$$^^^^^^^^^^^^^^
^^^$$$^^^^
'''
看上面的代码就能理解这道题怎么做了

该博客介绍了2018年Python二级考试的环境要求,即Windows7和Python3.5下的IDLE。文章重点讲解了Python的format方法,通过示例解释了如何使用format进行字符串格式化,特别是对占位符和对齐方式的运用。此外,还提供了多个代码示例来帮助理解不同参数如何影响输出结果。
517

被折叠的 条评论
为什么被折叠?



