关于python中换行问题
各位大佬们,请问为什么用\n换行符之后第二行开头会有空格出现?task = input()
t = task.split(',')
n = len(t)
if n%2==0:
print(f'{t},{t}\n{t},{t}')
else:
print(f'{t},{t},{t}\n{t},{t},{t}')
输入 defrost the fridge, return books to the library, boil sausages, walk the dog, buy tickets之后结果是这个:
defrost the fridge, return books to the library, boil sausages↩
boil sausages, walk the dog, buy tickets
就是在boil 之前有个空格。
因为你输入的时候b前面就有空格啊,代码例加一行打印
task = input()
t = task.split(',')
print(t)#加一行打印
n = len(t)
if n%2==0:
print(f'{t},{t}\n{t},{t}')
else:
print(f'{t},{t},{t}\n{t},{t},{t}')
从结果里很明显的可以看出来
defrost the fridge, return books to the library, boil sausages, walk the dog, buy tickets
['defrost the fridge', ' return books to the library', ' boil sausages', ' walk the dog', ' buy tickets ']
defrost the fridge, return books to the library, boil sausages
boil sausages, walk the dog, buy tickets 你看 昨非 发表于 2021-3-3 17:36
因为你输入的时候b前面就有空格啊,代码例加一行打印
从结果里很明显的可以看出来
我说怎么一直不对{:10_250:}。那请问该怎么让结果没有那个空格啊 木水盗人 发表于 2021-3-3 17:46
我说怎么一直不对。那请问该怎么让结果没有那个空格啊
输入的时候别加空格就好了啊 但是题目需要没有空格{:10_269:}
页:
[1]