四十七、list类
1、定义:
class list(object) | list() -> new empty list | list(iterable) -> new list initialized from iterable's items
2、解释:生成一个list 对象或者将一个迭代对象的所有迭代元素初始化为一个list对象。
另外list对象本身还有很多对应的方法,可以使用前面说的dir函数进行查看,这里不做介绍有机会后面会讲解:
>>> dir(list()) ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__delslice__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
3、举例:
>>> list('123asdfas') ['1', '2', '3', 'a', 's', 'd', 'f', 'a', 's'] >>> list((1,2,4,'a')) [1, 2, 4, 'a'] >>> list() []
四十八、locals方法
1、定义:
locals(...) locals() -> dictionary Update and return a dictionary containing the current scope's local variables.
2、解释:更新并返回包含当前程序概念作用域的本地变量
3、举例:
>>> locals() {'__builtins__': <module '__builtin__' (built-in)>, '__name__': '__main__', '__doc__': None, '__package__': None} >>> import datetime >>> locals() {'__builtins__': <module '__builtin__' (built-in)>, '__name__': '__main__', 'datetime': <module 'datetime' (built-in)>, '__doc__': None, '__package__': None}
四十九、long类
1、定义:
class long(object) | long(x=0) -> long | long(x, base=10) -> long | | Convert a number or string to a long integer, or return 0L if no arguments | are given. If x is floating point, the conversion truncates towards zero. | | If x is not a number or if base is given, then x must be a string or | Unicode object representing an integer literal in the given base. The | literal can be preceded by '+' or '-' and be surrounded by whitespace. | The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to | interpret the base from the string as an integer literal. | >>> int('0b100', base=0) | 4L
2、解释:该用法与int类似, 详见:http://aoyanming.com/blog/display/22
3、举例: 详见:http://aoyanming.com/blog/display/22
Copyright © 2021.aoyanming个人博客站
发表评论