Python学习记录——基本概念
2012-05-29 16:59
537 查看
Python数据类型:
在Python中有三种内建的数据结构——列表、元组和字典。
命令:help (list)
列表:list
week = [ 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' ]
week.append('Sunday')
元组:tuple
tuple和list类似,但tuple是只读的,就像字符串,定义完就不可以修改了。
week = ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday' )
字典:dict(dictionary)
字符串:str(string)
unicode:
集合:set
只读集合?:frozenset (貌似这个集合创建后不能修改)
2. 类的默认函数
__init__ 初始化的时候被创建。
__call__ 使得类地对象(注意是对象)具有callable功能,可以把对象当函数使用,如:A a; a()
__str__ 该函书必须返回字符串,可以用str(object)将非字符从转化为字符串,print的时候会调用该函书。
3. 内建函数
repr(...)
repr(object) -> string //obj==eval(repr(obj))
在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))
相关文章推荐
- JavaScript Bible的学习记录1 - HTML, Dom和JavaScript中的基本概念
- python 学习笔记第四章:基本概念
- 【学习记录】面向对象的基本概念5
- Python学习之心路历程------第一天:基本概念(1)
- python面向对象学习(一)基本概念
- Python学习笔记_01:基本概念介绍
- opencv学习记录1--基本概念(1)
- 网上一篇关于JavaScript基本概念初级讲解论坛贴的学习记录
- python学习1-基本概念
- 【原】Learning Spark (Python版) 学习笔记(一)----RDD 基本概念与命令
- [DB2 学习记录]3. DB2 基本安全概念-身份验证
- python学习笔记【一】--基本概念
- JavaScript基本概念初级讲解论坛贴的学习记录
- Python学习记录——Python基本语法
- python学习笔记(2)--基本概念
- Python 学习笔记(2) - 基本概念、运算符与表达式
- Box2D基本概念的学习记录
- Python学习记录一,基本的输入输出数据类型
- 【学习记录】面向对象的基本概念3
- Learning Spark (Python版) 学习笔记(一)----RDD 基本概念与命令