Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.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中打印字符之间带有破折号的字符串的函数?_Python_String_Function - Fatal编程技术网

如何定义在python中打印字符之间带有破折号的字符串的函数?

如何定义在python中打印字符之间带有破折号的字符串的函数?,python,string,function,Python,String,Function,我想定义一个函数(print\u with_破折号),这样它就可以打印字符串x,在字符之间插入破折号。在本例中,理想情况下打印h-e-l-l-o def print_with_dashes(x): print (x) print_with_dashes ('hello') 您可以使用函数 def print_with_dashes(x): print '-'.join(x) 演示: print('-'.join(x))所以您已经尝试。。。具体是什么?请解释一下你的答案 &g

我想定义一个函数(
print\u with_破折号
),这样它就可以打印字符串
x
,在字符之间插入破折号。在本例中,理想情况下打印
h-e-l-l-o

def print_with_dashes(x):
    print (x)

print_with_dashes ('hello')
您可以使用函数

def print_with_dashes(x):
    print '-'.join(x)
演示:


print('-'.join(x))
所以您已经尝试。。。具体是什么?请解释一下你的答案
>>> print_with_dashes('hello')
h-e-l-l-o
>>>