python里Chr什么意思
chr()函数用一个范围在range(256)内的(就是0~255)整数作参数,返回一个对应的字符.因此,不能返回一个汉字.
这个应该是你看错了.python中可以使用单引号,这个地方应该是写的两个单引号..
你可以用一下map方法,它的作用就是扩展单参数方法的处理能力,使你可以一次性送入一系列待操作参数,自动反复执行单参数方法.另外,看起来你是要处理大量字符的问题,有一个模块叫作struct,对你来说更加有用、高效.
>>> help(ord) Help on built-in function ord in module builtins:ord() #这是一个函数 ord(c) -> integer #接受一个参数,返回值是int,整数 Return the integer ordinal of a one-character string. #参数是长度为1的字符,返回它对应的整数 示例:>>>
l = []定义一个列表for i in range(3): # 循环输入3个数 range是生成一个序列 为了for循环使用的 x = int(raw_input('integer:\n')) # 输入一个数字 因为输入的是字符串 还要转换成整数 l.append(x) #把这个数字添加到列表中l.sort() # 对列表进行排序print l # 输出这个列表就是这个结果了integer:8integer:5integer:6[5, 6, 8]
sleep是等待多少秒 Python time sleep()方法 描述 Python time sleep() 函数推迟调用线程的运行,可通过参数secs指秒数,表示进程挂起的时间.语法 sleep()方法语法:time.sleep(t) 参数 t -- 推迟执行的秒数.返回值 该函数没有返回值.
s=u'中文'少了u prefix
实际a应该是'0x61',int应该是97,如果非要61就用下面的方法.int(hex(ord('a'))[2:])
逻辑根本不一样python 的for i in range(10),也就是for i in [0,1,2,3,4,5,6,7,8,9]不管你在循环体里对i做了什么,每次回到循环开始,i都会被重新赋值为list里的下一个元素,每次步进为1C语言代码由于循环体可以改变i,所以实际上是每次步进为1或3,结果当然不同
class Person: '''Represents a person.''' population = 0 def __init__(self, name): '''Initializes the person's data.''' self.name = name print '(Initializing %s)' % self.name # When this person is created, he/she # adds to the population Person.population