Python中文
首页
教程
问答
标签
搜索
登录
注册
python for循环迭代器和int(,16)
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我的查询用于以下示例:</p> <pre><code>c0b0="FF FF FF FF FF FF FF FF FF 7F" print c0b0 for ch in c0b0: a=str(ch) print "{0} {1}".format(ch,type(ch)) print hex(int(ch,16)) </code></pre> <p>如果您看到输出:</p> <pre><code>sh-4.3$ python main.py FF FF FF FF FF FF FF FF FF 7F F <type 'str'> 0xf F <type 'str'> 0xf <type 'str'> Traceback (most recent call last): File "main.py", line 8, in <module> print hex(int(ch,16)) ValueError: invalid literal for int() with base 16: '' </code></pre> <p>看到这一点,我们当然可以说ch不是元组而是字符串。但仍然int(ch,16)认为ch是无效的文本。你知道吗</p> <p>有人能指出我遗漏的地方,以及它将如何处理int(,16)吗?你知道吗</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>当您执行<code>for ch in c0b0</code>操作时,您是在初始字符串的各个字符上进行迭代,而不是在以空格分隔的十六进制数字对上进行迭代。您的代码在第一个空格处失败。你知道吗</p> <p>我认为您需要<code>for ch in c0b0.split()</code>,它首先将原始字符串分割成一个字符串列表(按空格分割),然后再遍历该列表。你知道吗</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
我想从用户inpu创建一个类的实例
2 回答
我想从用户导入值,为此
10 回答
我想从用户那里得到一个整数输入,然后让for循环遍历该数字,然后调用一个函数多次
10 回答
我想从用户那里收到一个列表,并在其中执行一些步骤,然后在步骤完成后将其打印回来,但它没有按照我想要的方式工作
2 回答
我想从用户那里获取输入,并将值传递给(average=dict[x]/6),然后在那里获取resu
4 回答
我想从第一个列表中展示第一个词,然后从第二个列表中展示十个词,以此类推- Python
1 回答
我想从第一个空lin开始解析文本文件
6 回答
我想从简历、简历中提取特定部分
2 回答
我想从给定字典(python)的字符串中删除\u00a9、\u201d和类似的字符。
4 回答
我想从给定的网站Lin下载许多文件扩展名相同的Wget或Python文件
3 回答
我想从网上搜集一些关于抵押贷款的数据
2 回答
我想从网站上删除电子邮件地址
2 回答
我想从网站上读取数据该网站包含可下载的文件,然后我想用python脚本把它发送给oracle如何?
1 回答
我想从网站中提取数据,然后将其显示在我的网页上
5 回答
我想从网页上提取统计数据。
8 回答
我想从网页上解析首都城市,并在用户输入国家时在终端上打印它们
9 回答
我想从色彩图中删除前n个颜色,而不丢失原始颜色数
2 回答
我想从课堂上打印字典里的键
2 回答
我想从费用表中获取学生上次支付的费用,其中学生id=id
6 回答
我想从较低的顺序对多重列表进行排序,但我无法在一行中生成结果
4 回答