为什么有空引号?

Why is there empty quotation marks?

给定一个字符串,return一个字符串,其中原始字符串中的每个字符都有两个字符。

double_char('The')'TThhee'

double_char('AAbb')'AAAAbbbb'

double_char('Hi-There')'HHii--TThheerree'

解决方案:

    def double_char(str):
      double_char = ""
      for i in range(len(str)):
        double_char += str[i]*2
      return double_char

您好,我是新来的,第一次发现这个网站并提出问题,如果有不明白的地方,请见谅。 有人可以详细解释一下吗?比如为什么它有空引号?

double_char = "" 创建一个空字符串,以便能够向其中添加字符。

for i in range(len(str)): 每一个字母

double_char += str[i]*2 将此字母添加到字符串中两次

return double_char Return 字符串

def double_char(str):            # function double_char takes argument str
    double_char = ""             # create an empty string assign to variable double_char. In python you put "" or '' around text that you want as a string (text).
    for i in range(len(str)):    # iterate from 0 to length of string
        double_char += str[i]*2  # append character at position i from str and duplicate it
    return double_char           # return double_char