小编Sta*_*low的帖子

在函数中迭代

我整天都在努力工作,但是我花了大约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.

python iteration function

3
推荐指数
1
解决办法
141
查看次数

标签 统计

function ×1

iteration ×1

python ×1