执行以下程序,输入”fish520”,输出结果是( )。 w=input() for x in w: if’0’

admin2020-04-10  8

问题 执行以下程序,输入”fish520”,输出结果是(    )。
  w=input()
  for x in w:
    if’0’<=x<=’9’:
        continue
    else:
       w.replace(x,")
  print(w)

选项 A、fish
B、fish520
C、520
D、520fish

答案B

解析 replace()方法的语法格式为:str.replace(old,new[,max]),把字符串中的old(旧字符串)替换成new(新字符串),返回一个新的字符串,如果指定第三个参数max,则替换不超过max次。本题中,for循环执行后,将依次返回新的字符串’ish520’、’fsh520’、’fis520’,这些新字符串对w并不影响,程序执行print(w)后输出’fish520’。故答案为B项。
转载请注明原文地址:https://kaotiyun.com/show/og6p777K
0

最新回复(0)