Python数据类型:
在Python中有三种内建的数据结构——列表、元组和字典。
命令:help (list)
列表:list
week = [ 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' ]
week.append('Sunday')
class list(object)
| list() -> new empty list
| list(iterable) -> new list initialized from iterable's items
元组:tuple
tuple和list类似,但tuple是只读的,就像字符串,定义完就不可以修改了。
week = ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday' )
class tuple(object)
| tuple() -> empty tuple
| tuple(iterable) -> tuple initialized from iterable's items
|
| If the argument is a tuple, the return value is the same object.
|
字典:dict(dictionary)
class dict(object)
| dict() -> new empty dictionary
| dict(mapping) -> new dictionary initialized from a mapping object's
| (key, value) pairs
| dict(iterable) -> new dictionary initialized as if via:
| d = {}
| for k, v in iterable:
| d[k] = v
| dict(**kwargs) -> new dictionary initialized with the name=value pairs
| in the keyword argument list. For example: dict(one=1, two=2)
|
| Methods defined here:
字符串:str(string)
class str(basestring)
| str(object) -> string
|
| Return a nice string representation of the object.
| If the argument is a string, the return value is the same object.
|
| Method resolution order:
| str
| basestring
| object
unicode:
class unicode(basestring)
| unicode(string [, encoding[, errors]]) -> object
|
| Create a new Unicode object from the given encoded string.
| encoding defaults to the current default string encoding.
| errors can be 'strict', 'replace' or 'ignore' and defaults to 'strict'.
|
| Method resolution order:
| unicode
| basestring
| object
集合:set
class set(object)
| set() -> new empty set object
| set(iterable) -> new set object
|
| Build an unordered collection of unique elements.
只读集合?:frozenset (貌似这个集合创建后不能修改)
class frozenset(object)
| frozenset() -> empty frozenset object
| frozenset(iterable) -> frozenset object
|
| Build an immutable unordered collection of unique elements.
2. 类的默认函数
__init__ 初始化的时候被创建。
__call__ 使得类地对象(注意是对象)具有callable功能,可以把对象当函数使用,如:A a; a()
__str__ 该函书必须返回字符串,可以用str(object)将非字符从转化为字符串,print的时候会调用该函书。
3. 内建函数
repr(...)
repr(object) -> string //obj==eval(repr(obj))