1. python 如何将ascii数字转换成字母求代码
尝试一下 chr 函数
2. 请问python 如何让字母和数字一 一对应 输入一个字母 可以转换为数字
因为“字母”是一个有限离散的集合,比较简单的处理方式是定义一个map:
letter_to_number={'A':1,'B':2}
letter='A'
number=letter_to_number[letter]#number=1
另外,如果这个转换关系恰好跟字母的ascii码值有某种函数关系的话,也可以这样:
letter='A'
number=ord(letter)-ord('A')+1#number=1
3. python 将数字转换成对应的英文数字
dic={'0':'zero','1':'one','2':'two','3':'three','4':'four','5':'five','6':'six','7':'seven','8':'eight','9':'nine'}
print 'plz input a number:'
n = raw_input()
s = str(n)
result = ''
for i in s:
result += dic[ i ]
result += ' '
print result
4. python中想要把字母或数字转为16进制\x30格式并且输出,但是最终显示却还是字母是怎么回事呢
给你一个函数试试。
def str_to_hex(s):
return ' '.join([hex(ord(c)).replace('0x', '') for c in s])
5. python如何将ascii码转换为字母
可以使用内置的chr()函数:
chr() 用一个范围在 range(256)内的(就是0~255)整数作参数,返回一个对应的字符。
比如chr(88) 会返回大写字母:X
与chr()函数相对应的函数是ord()函数,使用ord('X') 会返回:88
6. python中将阿拉伯数字转换为中文
第一种方案:
def num_to_char(num):
"""数字转中文"""
num=str(num)
new_str=""
num_dict={"0":u"零","1":u"一","2":u"二","3":u"三","4":u"四","5":u"五","6":u"六","7":u"七","8":u"八","9":u"九"}
listnum=list(num)
# print(listnum)
shu=[]
for i in listnum:
# print(num_dict[i])
shu.append(num_dict[i])
new_str="".join(shu)
# print(new_str)
return new_str
第二种方案
_MAPPING = (u'零', u'一', u'二', u'三', u'四', u'五', u'六', u'七', u'八', u'九', u'十', u'十一', u'十二', u'十三', u'十四', u'十五', u'十六', u'十七',u'十八', u'十九')
_P0 = (u'', u'十', u'百', u'千',)
_S4 = 10 ** 4
def _to_chinese4(num):
assert (0 <= num and num < _S4)
if num < 20:
return _MAPPING[num]
else:
lst = []
while num >= 10:
lst.append(num % 10)
num = num / 10
lst.append(num)
c = len(lst) # 位数
result = u''
for idx, val in enumerate(lst):
val = int(val)
if val != 0:
result += _P0[idx] + _MAPPING[val]
if idx < c - 1 and lst[idx + 1] == 0:
result += u'零'
return result[::-1]
7. Python的openpyxl模块中,列字母与数字之间转换的命令叫什么
函数get_column_letter已被重定位到Openpyxl版本2.4openpyxl.cell中openpyxl.utils。
目前接口在:from openpyxl.utils import get_column_letter
代码如下:
fromopenpyxl.utilsimportget_column_letter
fromopenpyxl.utilsimportcolumn_index_from_string
print(get_column_letter)
print(column_index_from_string)
输出:
<function get_column_letter at 0x000002489F407510>
<function column_index_from_string at 0x000002489F407598>
8. python 将英文字母转成对应的ASCII数字
1、创建python文件,testascii.py;