python数值型转换字符型_Python知识点练习-字符间转换、剔除元素

知识点:

1.字符串和字符的一些转换

2.剔除特殊数值的语句

3. for和return的缩进问题 (通过链接进行讲解)

python 缩进问题 - pursuer.chen - 博客园​www.cnblogs.com

4.不要马虎:( int(i) for i in 函数 if i !=0 )

题目:You are given a positive integer. Your function should calculate the product of the digits excluding any zeroes. For example, the number given is 123405. The result will be 1*2*3*4*5=120 (don't forget to exclude zeroes).

Input: A positive integer.

Output: The product of the digits as an integer.

正确解析:

d835f967ab1a30e3f9a7b0424cf8efc6.png

错误解析:

53b4a068e331692a64cbf4b5465275f9.png

错误原因:

[i for i in number_list if not i == 0]

In that i are strings, so it’s never == 0, but can == '0’.

注意注意注意!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值