这里会显示出您选择的修订版和当前版本之间的差别。
— |
python-basic:gramma [2011/03/25 05:00] (当前版本) |
||
---|---|---|---|
行 1: | 行 1: | ||
+ | ====== Python 语法基础 ====== | ||
+ | ===== Python 变量类型 ===== | ||
+ | Python是有变量类型的,而且会强制检查变量类型。\\ | ||
+ | 内置的变量类型有如下几种: | ||
+ | |||
+ | <code python> | ||
+ | #整型 | ||
+ | integer_number = 90 | ||
+ | |||
+ | #浮点 | ||
+ | float_number = 90.4 | ||
+ | |||
+ | #复数 | ||
+ | complex_number = 10 + 10j | ||
+ | |||
+ | #list 序列 | ||
+ | sample_list = [1,2,3,'abc'] | ||
+ | |||
+ | #dictionary 字典 | ||
+ | sample_dic = {"key":value, 2:3} | ||
+ | |||
+ | #tuple 只读的序列 | ||
+ | sample_tuple = (1,3,"ab") | ||
+ | |||
+ | #嵌套 | ||
+ | sample_nest = [(1,2,3),{1:2,3:4,'key':[1,2]},3] | ||
+ | </code> | ||
+ | ===== 一切都是对象 ===== | ||
+ | |||
+ | <code python> | ||
+ | 'str str'.split() # ['str', 'str'] | ||
+ | |||
+ | # 1..is_integer() # True | ||
+ | |||
+ | # is_integer(1) # True | ||
+ | |||
+ | # 1.0.is_integer() # False | ||
+ | |||
+ | [3,2,1].sort() # [1,2,3] | ||
+ | |||
+ | sort([2,1,3]) # [1,2,3] | ||
+ | </code> | ||
+ | |||
+ | |||
+ | ===== Python 程序流程控制 ===== | ||
+ | ==== 条件判断结构 ==== | ||
+ | <code python> | ||
+ | flag1 = some_value | ||
+ | flag2 = other_value | ||
+ | if flag1: | ||
+ | do_function_1() | ||
+ | elif flag2: | ||
+ | do_function_2() | ||
+ | else: | ||
+ | do_function_3() | ||
+ | </code> | ||
+ | |||
+ | ==== 循环结构 ==== | ||
+ | <code python> | ||
+ | for i in range(0, 10): | ||
+ | print(i) | ||
+ | |||
+ | for i in ['a','b','c','dd','eee']: | ||
+ | print(i) | ||
+ | </code> | ||
+ | |||
+ | |||
+ | ===== Python 标准库 ===== | ||
+ | Python 带有很丰富的标准库,给开发带来了很大的方便。 \\ | ||
+ | |||