python笔记--廖雪峰站学习笔记(二)
来源:互联网 发布:python 矩阵乘法 编辑:程序博客网 时间:2024/05/17 08:09
#生成一个从1到100的列表print(list(range(1,101)))#[1,2,3...,100]print([x * x for x in range(1,11) if x%2 ==0])#[4,16,36,64,100]print([x * x -1 for x in range(1,11) if x%3==1])#[0,15,48,99]print([x * x for x in range(1,11) if x%3==1])#[1,16,49,100]#二层循环,生成全排列print([m+n for n in 'abc' for m in 'xyz'])#使用os模块,遍历当前文件夹下的所有文件,只能说牛逼import osprint([d for d in os.listdir('.')])#在for循环中使用两个变量(类似foreach),遍历出字典dictdi = {'xiaoge':100,'xiaobai':90,'zz':80}for k,v in di.items():print(k,'=',v)#将数据字典dict转成列表listdi = {'xiaoge':'100','xiaobai':'90','zz':'80'}print([k + '=' + v for k, v in di.items()])#['xiaobai=90', 'xiaoge=100', 'zz=80']#将列表中的值转化成大小L = ['Xiaoge','Llll','Zhang','DAN']print([k.lower() for k in L])#遍历列表for k in L:print(k)#isinstance()函数判断变量的数据类型print(isinstance('xiaobai',int))#判断整型print(isinstance('xiaobai',str))#判断字符串#去掉数字和NoneL1 = ['Hello', 'World', 18, 'Apple', None]print([k for k in L1 if isinstance(k,str)])#得到下面结果:['Hello', 'World', 'Apple']
0 0
- python笔记--廖雪峰站学习笔记(二)
- python笔记--廖雪峰站学习笔记
- 廖雪峰Python学习笔记
- 廖雪峰python学习笔记
- 廖雪峰的Python学习笔记二-函数
- 廖雪峰 Python教程 笔记 二
- 廖雪峰python笔记
- 【廖雪峰】《安装Python》学习笔记
- 【廖雪峰】《Python基础》学习笔记
- 廖雪峰Python教程学习笔记
- 廖雪峰python教程学习笔记02
- 廖雪峰python学习笔记2:表
- 廖雪峰python学习笔记5:编码
- 廖雪峰python学习笔记7:函数
- 廖雪峰 Python教程 笔记
- 廖雪峰python学习笔记1:hello python
- 廖雪峰Python教程 学习笔记1 Python简介
- 廖雪峰Python教程 学习笔记2 安装Python
- c#中abstract、override、new、virtual、sealed使用和示例
- Linux设备驱动之中断与定时器
- HUST 1010(KMP应用:最短循环节点)
- Linux(CentOS) 下安装Redis
- jsp webshell代码
- python笔记--廖雪峰站学习笔记(二)
- ubuntu安装php7.0.3遇到的问题
- leetcode 9. Palindrome Number
- itext 处理中文问题 Font 'STSong-Light' with 'UniGB-UCS2-H' is not recognized 版本问题
- 居中+循环滚动的listview(1)
- Android Service的学习和总结
- Linux学习笔记--ln命令(链接命令)
- 判断一个字符串包含某个字符/截取指定字符窜
- 正则表达式