xrange属于类,继承自object. 用法: xrange(stop) -> xrange object xrange(start, stop[, step]) -> xrange object range属于函数,返回list,而xrange返回xrange object.对于循环而言,稍快于range(),内存效率更高.
#!/usr/bin/python # -*- coding: UTF- -*- n = for c in xrange(n): print c
format() 格式化输出字符串,format(value, format_spec)实质上是调用了value的__format__(format_spec)方法 "I am {0}, I like {1}!".format("wang", "moon") 'I am wang, I like moon!'