如何在Python中将ASCII转换为整数? [英] How to covert ASCII to integer in Python?

查看:338
本文介绍了如何在Python中将ASCII转换为整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有内置函数将ASCII转换为整数,反之亦然

在Python中?


谢谢!

Is there any built in function that converts ASCII to integer or vice versa
in Python?

Thanks!

推荐答案

John写道:
John wrote:

是否有内置函数将ASCII转换为整数或反之亦然
Python中的



谢谢!

Is there any built in function that converts ASCII to integer or vice versa
in Python?

Thanks!



您可能应该尽快通过教程位于:

http://docs.python.org / tut /

将ascii字符串转换为整数:


a =''1''

b = int( a)


将整数转换为ascii字符串:


a = 1

b = str(a)





a = 1

b ="%i" %a


-Larry Bates

You probably should go through the tutorial ASAP that is located here:

http://docs.python.org/tut/
Convert ascii string to integer:

a=''1''
b=int(a)

Convert integer to ascii string:

a=1
b=str(a)

or

a=1
b="%i" % a

-Larry Bates


2月22日下午5:43,John < rds1 ... @ sh163.netwrote:
On Feb 22, 5:43 pm, "John" <rds1...@sh163.netwrote:

是否有内置函数将ASCII转换为整数或反之亦然

in Python?


谢谢!
Is there any built in function that converts ASCII to integer or vice versa
in Python?

Thanks!



尝试int。

ie。


试试:

int_val = int(str_val)

除了ValueError:

#转换失败


Keir。


-

Keir Robinson

有时尖叫声比论文好。 (艾默生)

Try int.
ie.

try:
int_val = int(str_val)
except ValueError:
# conversion failed

Keir.

--
Keir Robinson
Sometimes a scream is better than a thesis. (Emerson)


John写道:
John wrote:

是否有内置函数将ASCII转换为整数或副
$ b $在Python中也是如此?


谢谢!
Is there any built in function that converts ASCII to integer or vice
versa in Python?

Thanks!

>> int(''10'')
>>int(''10'')



10

10


>> str(10 )
>>str(10)



''10''

''10''


>>>
>>>


这篇关于如何在Python中将ASCII转换为整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆