在函数中迭代

Sta*_*low 3 python iteration function

我整天都在努力工作,但是我花了大约4个小时来研究一个可能的答案,因为我喜欢自己发现事情,但我似乎无法靠近.

我正在编写一个带字符串的函数,我必须将每个字符转换为符号,不包括空格和短划线.

我也试过为它创建一个银行系统,但似乎它只迭代第一个元素,这是否与返回有关?

def get_view(puzzle): 
  for elements in puzzle:
      new_ string = elements.replace(elements, "$")
      return new_string 
Run Code Online (Sandbox Code Playgroud)

编辑:我试过:

HIDDEN ="^"new_string =""

def get_view(puzzle):
    for elements in puzzle:
    new_string = puzzle.replace(elements, HIDDEN)
    return new_string                  
Run Code Online (Sandbox Code Playgroud)

而现在又回来了

get_view("abc")'ab ^'

Wtttfffff.

ars*_*jii 5

它确实与此有关return.当return遇到语句,函数过程终止; 因此,for函数的-loop将始终在第一次迭代时结束.