变量
- 变量:
- 命名:字母数字下划线,不能以数字开头
字符串
- title()
- upper()
- lower()
- 制表\t 换行\n
- rstrip() lstrip() strip()
- 注意单引号和双引号使用
- python2中print 可以不带括号。。。
- str()其他类型转字符串类型
- import this
列表
- palyers=[‘charles’,‘martina’,‘michael’,‘florence’,‘eli’]
- palyers[0].title()
- players[1]=‘modify’
- players.append(‘add’)
- players.insert(0,‘ins’) 插入元素到指定位置
- del players[0] 删除指定元素
- players.pop() 弹出最后的元素
- players.pop(1) 弹出任何位置的元素
- players.remove(‘eli’)
- palyers.sort() 对列表永久性排序
- sorted(players) 对列表临时排序
- players.reverse() 永久性反转列表排列顺序
- len(players) 列表长度
- players[-1] 列表最后一个元素
- players[-3:] 倒三到最后个元素 切片
- palyers[2:4] 第3-4元素的切片、
- 切片是列表的副本 变量是列表本身
列表操作
- for player in players:
print player - for value in range(1,4):
print value - numbers=list(range(1,6))
- even_numbers=list(range(2,11,2))
- value**2
- digits=[1,2,3,4,5,6]
- min(digits)
- max(digits)
- sum(digits)
- squares=[value**2 for value in range(1,11)]
元组
- dim=(1,222) 元组内元素不能改变 元组变量可以改变