Python_基本数据结构示例
来源:互联网 发布:cf手游刷枪软件绿色版 编辑:程序博客网 时间:2024/04/29 08:54
#if条件语句x=int (input("please input an integer:"))if(x<60): print("Not pass")elif(x<70): print("you got D")elif(x<80): print("you got C")elif(x<90): print("you got B")else: print("you got A")
#for循环语句for i in range(1,10): for j in range(1,i+1): print('%s*%s=%s\t'%(j,i,i*j),end='') print()
#排序>>> s1=[1,3,2,5,4]>>> sorted(s1)[1, 2, 3, 4, 5]>>> reversed(s1)<list_reverseiterator object at 0x0000000002562780>>>> s1.sort()>>> s1[1, 2, 3, 4, 5]>>> s1.reverse()>>> s1[5, 4, 3, 2, 1]
>>> a=[1.0,2.0]>>> b=[1,2]>>> a==bTrue>>> c=(1,2)>>> d=(1,2,-1)>>> c<dTrue
#列表list>>> s1=list(map(lambda x:x**2,range(10))) #关于lambda函数http://blog.csdn.net/hpu_a/article/details/50244687>>> s1[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]>>> s2=[x**2 for x in range(10)]>>> s2[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]>>> s3=[(x,y) for x in range(10) for y in r>>> s3[(0, 0), (1, 2), (2, 4), (3, 6), (4, 8)]
#集合set>>> a = set('abcagd')>>> b = set('abcdef')>>> a{'a', 'c', 'g', 'd', 'b'}>>> b{'a', 'c', 'f', 'b', 'd', 'e'}>>> a - b{'g'}>>> a | b{'a', 'g', 'c', 'f', 'b', 'd', 'e'}>>> a & b{'a', 'c', 'd', 'b'}>>> a ^ b{'g', 'e', 'f'}>>> {x for x in a if x not in b}{'g'}
#字典dict>>> dic={'one':1,'two':2,'three':3}>>> dic{'one': 1, 'three': 3, 'two': 2}>>> dic('four')=4 File "<stdin>", line 1SyntaxError: can't assign to function call>>> dic['four']=4>>> dic{'one': 1, 'three': 3, 'two': 2, 'four': 4}>>> list(dic.keys())['one', 'three', 'two', 'four']>>> sorted(dic.keys())['four', 'one', 'three', 'two']>>> {x : x**2 for x in range(5)}{0: 0, 1: 1, 2: 4, 3: 9, 4: 16}
>>> l=[1,2,3,4,5,6]>>> a=dict([(v,v*10) for v in l])>>> a{1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}
for x,y in dic.items(): print(x,y)two 2four 4three 3one 1
0 0
- Python_基本数据结构示例
- python_基本类型
- OpenCV—基本数据结构与示例
- OpenCV的基本数据结构及示例
- OpenCV—基本数据结构与示例
- python_
- 基本示例
- 14-python_内建函数-基本和转换
- 【20170929】python_语言设计(1)基本语法
- 基本数据结构
- 基本数据结构
- 基本数据结构
- 基本数据结构
- 基本数据结构
- 基本数据结构
- 基本数据结构
- 数据结构--基本数据结构
- (总结)数据结构之链表的基本操作说明和示例(待补充)
- Objective-c语言_设置器和访问器
- osgearth访问几种数据的几种方式
- Android布局之scaleType属性
- MySQL数据类型
- Proguard语法及常用proguard.cfg代码段
- Python_基本数据结构示例
- ubuntu 无法解析主机的解决方法
- visual studio下实现图形函数调用
- 154 Which three statements are true about persistent configuration? (Choose three.) A. A user cannot
- Ansible :一个配置管理和IT自动化工具
- Linux域名解析得到ip地址
- VolleySupport使用说明
- 二叉排序树
- HBase写数据过程