python sep函数
sep parameter stands for separator, it uses with the print() function to specify the separator between the arguments.
sep参数代表分隔符,它与print()函数一起使用以指定参数之间的分隔符。
The default value is space i.e. if we don't use sep parameter – then the value of the arguments is separated by the space. With the "sep", we can use any character, an integer or a string.
默认值为空格,即,如果我们不使用sep参数 ,则参数的值由空格分隔。 使用“ sep” ,我们可以使用任何字符,整数或字符串。
Note: "sep" is available in Python 3.x or later versions.
注意: “ sep”在Python 3.x或更高版本中可用。
Syntax:
句法:
print(argument1, argument2, ..., sep = value)
在print()中带有'sep'参数的Python示例 (Python examples with 'sep' parameter in print())
Example 1:
范例1:
# variables
name = "Mike"
age = 21
city = "Washington, D.C."
# printing without using sep parameter
print("Without using sep parameter...")
print(name, age, city)
print()
# printing with using sep parameter
# separated by spaces
print("With using sep parameter (separated by spaces)")
print(name, age, city, sep=' ')
print()
# printing with using sep parameter
# separated by colon (:)
print("With using sep parameter (separated by colon)")
print(name, age, city, sep=':')
print()
# printing with using sep parameter
# separated by " -> "
print("With using sep parameter (separated by ' -> ')")
print(name, age, city, sep=' -> ')
print()
Output:
输出:
Without using sep parameter...
Mike 21 Washington, D.C.
With using sep parameter (separated by spaces)
Mike 21 Washington, D.C.
With using sep parameter (separated by colon)
Mike:21:Washington, D.C.
With using sep parameter (separated by ' -> ')
Mike -> 21 -> Washington, D.C.
Example 2:
范例2:
# variables
name = "Mike"
age = 21
city = "Washington, D.C."
# printing with using sep parameter
# disable space separator
print("With using sep parameter (disable space separator)")
print(name, age, city, sep='')
print()
# printing with using sep parameter
# separated by number
print("With using sep parameter (separated by number)")
print(name, age, city, sep='12345')
print()
# printing with using sep parameter
# separated by " ### "
print("With using sep parameter (separated by ' ### ')")
print(name, age, city, sep=' ### ')
print()
Output:
输出:
With using sep parameter (disable space separator)
Mike21Washington, D.C.
With using sep parameter (separated by number)
Mike123452112345Washington, D.C.
With using sep parameter (separated by ' ### ')
Mike ### 21 ### Washington, D.C.
翻译自: https://www.includehelp.com/python/sep-parameter-in-python-with-print-function.aspx
python sep函数