BenDanYang 发表于 2018-6-23 08:40:05

#每日一问#

def Dec2Bin(dec):
    result = ''
   
    if dec:
      result = Dec2Bin(dec//2)
      return result + str(dec%2)
    else:
      return result

print(Dec2Bin(10))

这段十进制转换二进制代码中的 result = ‘’为什么要写出来的?谢谢大家咯

ba21 发表于 2018-6-23 09:35:56

result 先初始化为 ''空字符,以便 后面 用来连接个个字符

BenDanYang 发表于 2018-6-23 11:02:09

ba21 发表于 2018-6-23 09:35
result 先初始化为 ''空字符,以便 后面 用来连接个个字符

哦,明白了。
页: [1]
查看完整版本: #每日一问#