为什么int(12,16)会报错

核动力蜗牛Killua 2010-05-11 04:36:06

>>> int (12,16)

Traceback (most recent call last):
File "<pyshell#41>", line 1, in <module>
int (12,16)
TypeError: int() can't convert non-string with explicit base


函数int(obj,base = 10),这样用应该没错的啊?

哪位大大能稍微讲解下
...全文
379 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
angel_su 2010-05-11
  • 打赏
  • 举报
回复
练练e文先...
fibbery 2010-05-11
  • 打赏
  • 举报
回复
can't convert non-string with explicit base

这不是挺清楚的吗?
notax 2010-05-11
  • 打赏
  • 举报
回复

>>> help(int)


class int(object)
| int(x[, base]) -> integer
|
| Convert a string or number to an integer, if possible. A floating point
| argument will be truncated towards zero (this does not include a string
| representation of a floating point number!) When converting a string, use
| the optional base. It is an error to supply a base when converting a
| non-string. If the argument is outside the integer range a long object
| will be returned instead.


>>> int ('12', 16)
18
>>>

  • 打赏
  • 举报
回复
忘记说了,我说的是python

37,719

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧