首页 > 编程语言 > 详细

python笔记

时间:2018-06-20 20:16:30      阅读:156      评论:0      收藏:0      [点我收藏+]

已经学习了两周的python,现在将自己这几天做的笔记传上来

  1 1.变量名
  2     -由字母,数字,下划线组成
  3     -数字不能开头
  4     -不能是关键字 and as assert break class continue def del elif else except exec finally for from global if import in is lambda not or pass print raise return try while with yield
  5     -驼峰命名法 youName you_name
  6 
  7 2.条件语句
  8     -if
  9         缩进用4个空格
 10         if 条件:
 11             print("123")
 12         else:
 13             print("456")
 14         if嵌套
 15             if 1==1 16                 if 2==2 17                     print("123")
 18                 else:
 19                     print("456")
 20         if elif
 21             int = input("请输入:")
 22             if int > 5:
 23                 print("A")
 24             elif int == 5:
 25                 print ("B")
 26             else:
 27                 print ("C")
 28             print("end")
 29         pass 占位
 30             if 1==1:
 31                 pass
 32             else:
 33                 print(sb)
 34         and or
 35             if n1 == "alex" or n2 == "alex!23":
 36                 print(OK)
 37             else:
 38                 print(NO)
 39     -while
 40         n1 = 1
 41         while n1 <= 100:
 42             print(n1)
 43             n1 += 1
 44         print("end")
 45         死循环
 46             while True:
 47                 youName = inpurt("输入你的名字:")
 48                 print(youName)
 49     -for
 50         循环遍历
 51             n1 = [1,2,3,4,5,6]
 52             for n2 in n1:
 53                 print(n2)
 54             else:
 55                 print ("end")
 56     -break
 57         跳出for 和 while 循环 循环终止
 58     -continue
 59         跳出本次后面循环,进入下一次循环
 60                 
 61 3.数据类型
 62     -字符串 str
 63         用引号引起  “” ‘’ “““””” ‘‘‘’’’
 64         youName = wds
 65         加法 n1 = you n2 = is n3 = sb n4 = n1 + n2 + n3
 66         乘法 n3 = sb n5 = n3 * 3
 67         -**join() 将字符串中每一个元素按照指定分隔符进行拼接
 68         -format(wds) 给{}传值
 69         -format_map({}) 传字典
 70         -capitalize()首字母大写
 71         -swapcase() 大小写转换
 72         -casefold()大写转小写
 73         -**lower() 大写转小写
 74         -islower() 是否是小写
 75         -**upper() 小变大
 76         -isupper() 是否大写
 77         -lstrip()
 78         -rstrip()
 79         -**strip()   去除
 80         -partition(i) 以i分割
 81         -rpartition()
 82         -**split(i,2) 以i分割两次,取不到i
 83         -splitlines() 以换行符分割 True 保留 \n False 不保留
 84         -center(20,*)设置宽度,内容居中,以*填充空白
 85         -ljust(20,*)内容左
 86         -rjust(20,*)内容右
 87         -zfill(20) 000填充
 88         -count(i,5)计算当前字符串中1出现的频率,可设置起始位置,结束位置
 89         -endswith(id) 以id结尾
 90         -startwith(id) 以id开头
 91         -**find(id)从开始找id的第一个位置  -1 表示没找到
 92         -index()  找索引
 93         -expandtabs(20) 断句20,出现/t 补齐 /n换行
 94         -isalnum() 判断字符串中是否只有数字和字母
 95         -isalpha() 判断字母
 96         -isdecimal() 判断数字
 97         -isdigit() 判断数字
 98         -title()变成标题
 99         -istitle()是否是标题    
100         -**索引,下标  获取字符串中的字符
101         -**切片
102         -**len() 获取字符串长度
103         -**for循环
104         -range(100,5)创建连续数字,用步长表示间隔
105         -**replace()替换
106     -整型 int
107         age = 18
108         + - * / // %
109         // 取余 9 // 2 = 1
110         % 取整  9 % 2 = 4
111         -int()将字符串转换为数字
112         -bit_length()数字的二进制至少由几位表示
113     -列表 list
114         -[] 括起来
115         -, 分割
116         -元素可以是数字,字符串,列表,布尔值
117         -索引取值
118         -切片 切片结果也是列表
119         -for循环
120         -while 循环
121         -修改
122             li[2] = 123
123             li[1:3] = [123,466]
124         -删除
125             del li[2]
126             del li[2:5]
127         -list()
128         -None 空值
129         -append() 整体追加到原列表
130         -clear() 清空列表
131         -copy() 复制
132         -count() 计算元素出现的次数
133         -extend() 遍历追加到原列表
134         -index() 找索引
135         -insert() 在指定索引位置插入
136         -pop() 索引删除 默认最后一个元素
137         -remove() 元素删除 
138         -reverse() 将当前列表反转
139         -sort() 排序
140     -元祖 tuple
141         -() 
142         -元素不可被修改,不能被增加或者删除
143         -习惯元祖元素最后加一个逗号
144         -可索引,切片取值
145         -元组的一级元素不可修改,元祖内的列表可修改
146         -count()
147         -index()
148     -字典 dict
149         -{k1:123,k2:456}键值对
150         -value 可任意值
151         -key 数字,字符串,元祖
152         -无序
153         -keys()
154         -values()
155         -for k,v in info.items:
156             print(k,v)
157         -fromkeys() 根据序列,创建字典    
158         -get() 
159         -pop() 删除
160         -setdefault()
161         -update() 更新键值
162     -布尔值 bool
163     整理
164 
165         一、数字
166             int(..)
167         二、字符串
168             replace/find/join/strip/startswith/split/upper/lower/format
169             tempalte = "i am {name}, age : {age}"
170             # v = tempalte.format(name=‘alex‘,age=19)
171             v = tempalte.format(**{"name": alex,age: 19})
172             print(v)
173         三、列表
174             append、extend、insert
175             索引、切片、循环
176         四、元组
177             忽略
178             索引、切片、循环         以及元素不能被修改
179         五、字典
180             get/update/keys/values/items
181             for,索引
182             dic = {
183                 "k1": v1
184             }
185 
186             v = "k1" in dic
187             print(v)
188 
189             v = "v1" in dic.values()
190             print(v)
191         六、布尔值
192             0 1
193             bool(...)
194             None ""  () []  {} 0 ==> False
195         
196 4.运算符
197     算数    + - * / // %
198     成员    in    not in
199     布尔值    True 真 False 假
200     比较    ==   <  >  <=  >=  !=  <>不等于
201     逻辑    and  or  not202     赋值    += -= /= *= //= %= **=
203     
204 5.集合
205     -由不同元素组成
206     -无序
207     -集合中元素必须是不可变类型
208     -set()遍历
209     -add()添加
210     -clear() 
211     -copy()
212     -pop()
213     -remove()传参删除
214     -discard()删除不报错
215     -intersection() 交集        
216     - & 交集
217     -union() 并集
218     - | 并集
219     -difference() 差集
220     - - 差集
221     -symmetric_difference()交叉补集
222     - ^ 交叉补集
223     -isdisjoint()有交集返回True
224     -issubset() 子集
225     -issuperset() 父集
226     -update() 更新多个值
227     -
         
2018-06-2018:38:50

 

python笔记

原文:https://www.cnblogs.com/wxszxyll/p/9205410.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!