Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python中拆分消息_Python_Python 3.x - Fatal编程技术网

在python中拆分消息

在python中拆分消息,python,python-3.x,Python,Python 3.x,好的,这只是tfi字符串的一小部分,但是如何让代码在由字符数量决定的部分中打印出来呢 伪: tfi = ''' aardvark albatross alligator alpaca ant anteater antelope ''' print(tfi) 等等…试试这个: print tfi (3 chars): returns: 'aar' 'dva' 新消息是什么?输出aar前3个字符、dva秒等的示例。您需要编辑以使其清晰。非常感谢 def tfi(my_strin

好的,这只是tfi字符串的一小部分,但是如何让代码在由字符数量决定的部分中打印出来呢

伪:

tfi = '''
aardvark
albatross
alligator
alpaca
ant
anteater
antelope
'''

print(tfi)
等等…

试试这个:

print tfi (3 chars):
returns:
    'aar'
    'dva'

新消息是什么?输出aar前3个字符、dva秒等的示例。您需要编辑以使其清晰。非常感谢
def tfi(my_string, dif):
    for i in range(0, len(my_string), dif):
        print(my_string[i:i+dif])