python 定义字符串的打印模式

oknwwptz  于 2023-01-24  发布在  Python
关注(0)|答案(1)|浏览(113)
def print_string(ABC):
   
    for r in range(7):
        for cur_char in ABC:
            for c in range(6):
                print(cur_char[r,c],end="")
        print("")

TypeError: string indices must be integers
我什么都没试过。

vsnjm48y

vsnjm48y1#

Python中的子字符串使用:作为分隔符。

string[start:end:step] # From start to end (exclusive) each step-th
                       # character (meaning 0th, 2nd, 4th ... for step=2)
string[start:]         # From start
string[:end]           # From 0 to end (exclusive)

所以在你的例子中:

print(cur_char[r:c],end="")

更多关于Python中的子字符串:https://www.freecodecamp.org/news/how-to-substring-a-string-in-python/

相关问题