Skip to main content
 首页 » 编程设计

python之前导和尾随 '0' 给出错误

2025年05月04日18bhlsheji

random.randint(50,9) 

或

random.randint(5,09) 

给出错误,虽然只是

random.randint(5,9) 

..有效!

如果不将其转换为字符串或使用 x.f 格式,python 中不允许前导和尾随零吗?

请您参考如下方法:

哦,亲爱的。 “尾随”零给出错误,因为 first argument to randint should be smaller than the second .

与许多其他语言一样,前导零用于表示 python-2.x 中的八进制数。