字符串重复
import sys
import math
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
n = int(input())
string = input()
# 如果string不为空
if string and n:
print(n*string)
else:
print("empty")
组建图形
import sys
import math
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
chr_1, chr_2, chr_3 = input().split()
print(chr_1 * 5)
print(chr_1, chr_2 * 3, chr_1, sep='')
print(chr_1, chr_2, chr_3, chr_2, chr_1, sep='')
print(chr_1, chr_2 * 3, chr_1, sep='')
print(chr_1 * 5)
这里注意
end 参数:用于指定在输出结束后添加的字符。默认情况下,print 函数在输出结束后会添加一个换行符 \n。消除这个换行符,可以将 end 参数设置为空字符串 ‘’(就是\n变成“”)
sep 参数:用于指定多个参数之间的分隔符。默认情况下,print 函数在输出多个参数时会在它们之间添加一个空格。消除这个空格,可以将 sep 参数设置为空字符串 ‘’。
字符串大小写处理
import sys
import math
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
n = int(input())
for i in range(n):
row = input()
print(''.join([row[i].upper() if i % 2 == 0 else row[i].lower() for i in range(len(row))]))
各自位置上面处理加入到列表,最后Join组合起来