Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.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 3.x 如何删除字符串上第一项之前的间距?_Python 3.x - Fatal编程技术网

Python 3.x 如何删除字符串上第一项之前的间距?

Python 3.x 如何删除字符串上第一项之前的间距?,python-3.x,Python 3.x,例如: 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小时 print("The time you entered, {}, is {} in the 12-hour format.".format(time, Time)) 我希望14:06之后的空间消失,这样看起来

例如:

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小时

print("The time you entered, {}, is {} in the 12-hour format.".format(time, Time))
我希望14:06之后的空间消失,这样看起来就像这样:

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

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

PS:
时间
是标准库的一个模块。我建议您改用
time24
time12

PS:
时间
是标准库的一个模块。我建议您改用
time24
time12

sep='
添加到
打印
语句中。这是
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.

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.