1. python学习网站
2. 脚本开始
#! /usr/bin/env python
3. python 中单引号和双引号是等效的,在双引号中要体现字符串用单引号
print "hello world 'nihao'"
>>> 1/3 0 >>> 1/3.0 0.3333333333333333python 做不同数值类型的计算挺方便的,和计算器一样好使!
''' |_H_|_e_|_l_|_p_|_A_| 0 1 2 3 4 5 -5 -4 -3 -2 -1 0 '''
word[0:2]---> He word[0:2:1]---> He word[:2]---> He word[5:0:-1]---> Aple word[5::-1]---> ApleHword[ start : end : step ] : start->起始标号对应的元素,end-> 对应小于end标号的元素,注意是小于,0:2 就是0、1两个元素!
>>> a = ['spam', 'eggs', 100, 1234] >>> a
['spam', 'eggs', 100, 1234]dictionaries 字典类型,也就是键值对应:
tel = {"jack":4098, "harry":1024} >>> tel {'jack': 4098, 'harry': 1024} >>> tel['jack'] 4098 >>> tel["jack"] = 456 >>> tel {'jack': 456, 'harry': 1024}7. python中是区分大小写的。
>>> hex(10) '0xa' >>> int('0xa',base = 16) 10
>>> range(0,10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> range(0,10,2) [0, 2, 4, 6, 8]
i = 10 def test1(): if i == 10: print 'success!' else: print 'fail!' print test1() def test2(): for i in word: print i return "yes" print test2()注意加冒号的位置,if中要执行多条语句用逗号隔开!