如何定义一个可以与不同变量一起使用并在python中生成输出的函数?

时间:2017-11-02 16:47:59

标签: python

我曾尝试使用此函数在变量完成内创建输出,但似乎没有任何效果

punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~ '''

def puncrem(x,y):
    for char in str(x):
       if char not in punctuations:
           y = y + char
    return y 


start = "h%e*l(l&o"

finish = ""

puncrem(start,finish)

print(finish)

1 个答案:

答案 0 :(得分:0)

你必须使用这样的返回值:

punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~ '''

def puncrem(x):
    y = ""
    for char in str(x):
        if char not in punctuations:
            y = y + char
    return y

start = "h%e*l(l&o"
finish = puncrem(start)
print(finish)