|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
各位大佬们,请问为什么用\n换行符之后第二行开头会有空格出现?
- task = input()
- t = task.split(',')
- n = len(t)
- if n%2==0:
- print(f'{t[0]},{t[1]}\n{t[2]},{t[3]}')
- else:
- print(f'{t[0]},{t[1]},{t[2]}\n{t[2]},{t[3]},{t[4]}')
复制代码
输入 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[0]},{t[1]}\n{t[2]},{t[3]}')
- else:
- print(f'{t[0]},{t[1]},{t[2]}\n{t[2]},{t[3]},{t[4]}')
复制代码
从结果里很明显的可以看出来
- 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
复制代码
|
|