2016-09-14 72 views
1

例子:如何在字符串的第一个项目之前删除空格?

time = "14:06" 
Time = "2:06 PM" 

print("The time you entered,",time,", is",Time,"in the 12-hour format.") 

此打印:您输入的时间,14:06,是下午2点06分的12小时格式。

我想要的空间后14:06至消失,这样它会看起来像这样:

您输入的时间,14:06,是下午2点06分在12小时格式。

回答

0

sep=''加到print声明中。这是print语句中所有项之间的自定义分隔符(在Python3中)。然后您将需要手动添加正确的间距。

time = "14:06" 
Time = "2:06 PM" 

# Original print statement 
print("The time you entered,",time,", is",Time,"in the 12-hour format.", sep='') 

# Updated print statement 
print("The time you entered, ",time,", is ",Time," in the 12-hour format.", sep='') 

输出:

# Original 
The time you entered,14:06, is2:06 PMin the 12-hour format. 

# Updated 
The time you entered, 14:06, is 2:06 PM in the 12-hour format. 

https://docs.python.org/3/library/functions.html?highlight=print#print

相关问题