糯康老婆,姜瑶,黄鹤楼漫天游香烟
计算机五大结构:输入设备,存储器,控制器,运算器,输出设备
存储器与运算器统称为cpu
计算机操作系统负责管理计算机硬件资源->系统调用
编程是人与计算机的互动方式,人通过编程来操纵计算机完成事情.
编程范式:过程式编程,面向对象编程,函数时编程.python是多范式语言.
封装
模块是比函数更高一级的,文件的复用
优点: 易读.实用,可拓展性好
缺点:运行不如c
特点:
>>> 1+5 # 加 6 >>> 2-3 #减 -1 >>> 1*6 #乘 6 >>> 6/2 #除法默认浮点 3.0 >>> 6.0/3 #浮点 2.0 >>> 6/3.0 #浮点 2.0 >>> 18//4 #取商 4 >>> 18%4 #取余 2 >>> 4**2 #乘方 16
>>> 'hi'*2 #字符串乘法 'hihi' >>> 'hi'+'hello' #字符串加法 'hihello'
>>> true true >>> false false
>>> true and true true >>> false and true false >>> false and false false >>> not true false
>>> 1 == 1 true >>> 8.0 != 8.0 false >>> 4 < 5 true >>> 3 <= 3 true
>>> 6>2 and 4>3 and 1>2 #多组判断 false
** 乘方 * / 乘除 + - 加减 == >= <= > < ! = 判断 not and or 逻辑
计算中,括号先行是万能的
高优先级先运算,相同优先级从左到右
>>> 4+2>=7 #优先级顺序 false >>> 1>2 and 4<3 or 6>2 true >>> 1>2 and (4<3 or 6>2) false
>>> 4*2 and 6-3 # 数字无法判读 3 >>> 5 and 5 #数字无法判断 5
变量名直接参与运算是迈向抽象思维的第一步.数学上,符号代替数值的做法称为代数.-->变量提供的符号化表达方式是代码复用的第一步.
>>> wood =5 # =表示赋值 >>> wood = wood+5 # 计算机先执行赋值符号右边的运算, >>> print(wood) 10 >>> 6 = n #赋值号左边只能是变量名,赋值语句 syntaxerror: can't assign to literal
>>> a = 100 #int >>> b = 100.0 #float >>> a = 'abc' #str,字符串就是一串字符串起来 >>> a = true #bool
python中变量的类型是可以自由变化的,变量的类型由存储的数据决定,被称为动态类型.
>>> import keyword >>> print (keyword.kwlist) ['false', 'none', 'true', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
2. 赋值语句:赋值语句先执行等号右边,等号左边只能是变量
>>> example_list = [true,5,'smile'] # 创建列表 >>> type(example_list) # 查看类型,type()函数查看类型 <class 'list'> >>> example_tuple = (1,2,1.3,'love',false) #创建一个元祖 >>> type(example_tuple) #查看类型 <class 'tuple'> >>> kong_list = [] #创建空列表
>>> example_tuple = (1,2,1.3,'love',false) # 逗号表示并列 >>> example_tuple[0] #提取元祖中第一个元素 1 >>> example_list = [true,5,'smile'] >>> example_list[2] #提取列表中第三个元素 'smile' >>> nest_list = [1,[3,4,5]] #列表中嵌套列表 >>> nest_list[1][2] #提取第二个列表中的第三个元素 5
>>> example_tuple[:5] #从下标0到下标4,不包括下标5的元素.冒号表示继续 (1, 2, 1.3, 'love', false) >>> example_tuple[2:] #从下标2到最后一个元素 (1.3, 'love', false) >>> example_tuple[0:5:2] #从下标0,2,4的元素.每间隔两个取值 (1, 1.3, false) >>> example_tuple[0:5:2] (1, 1.3, false) >>> a = example_tuple[0:5:2] >>> type(a) # 范围引用结果还是元祖 <class 'tuple'> >>> a (1, 1.3, false)
>>> example_tuple[-1] # 序列最后一个元素 false >>> example_tuple[1:-1] #序列第二个到倒数第二个元素->范围引用不包括上限 (2, 1.3, 'love')
>>> example_list[1]=3.0 #更改列表中的第二个元素为3.0 >>> example_list [true, 3.0, 'smile']
词典是可以容纳多个无顺序数据的容器,词典允许用自定义(自由)的方式建立数据的索引,而不是采用下标(因为无顺序)
>>> example_dict={'tom':11,'sam':57,'lily':100} #创建词典 >>> type(example_dict) <class 'dict'> >>>example_dict={'hi':16,'hello':59,'free':99} #创建词典 >>>print(example_dict['hi']) #提取词典元素,打印hi对应的值 >>>example_dict['lilei']=59 #添加词典元素 >>>print(example_dict)# 打印词典 >>>example_dict={}#创建空词典 16 {'hi': 16, 'hello': 59, 'free': 99, 'lilei': 59}
一般用字符串作为词典的键,但其他数据也可以.
开始时,计算机程序是按照顺序由上到下执行,我们需要编写大量重复的语句,因此,人们开始琢磨哪些更改语句执行顺序的方法,使得语句执行可以跳转.但是人们发现,有跳转的语句使得程序读起来像面条一样,很是费劲,所以简化发现,跳转主要功能就是选择&循环,人们创建了选择语句与循环语句.通过选择语句与循环语句的编写,使得计算机程序进入结构化的时代.
>>> i=3 >>> if i>2: print('hi') else: print('why') hi
#遍历词典,但是只能提取出值 for i in {'hello':6,'hi':5}: print(i) hello hi
#循环打印1到9 for i in range(1,10): print(i) # 循环打印0到4,从0计数 for i in range(5): #从0开始计数 print(i)
#while无限循环 while true: print('hello world') # while条件循环 while i>2: #无限循环 print('hi') i=3 while i>2:#条件为真才会执行循环,语句体中应该有使得条件为假的语句 print(i) #从3开始打印数,到永远 i=i+1 i=9 while i>2:#打印9到3 print(i) i=i-1# 使得条件为假
#continue:停止此次循环,进入下一次循环 # 打印出9到5,到4时处于死循环状态 i=9 while i>2:#打印9到5 if i==4: continue print(i) i=i-1# 使得条件为假 # 打印出9到5,到4时处于死循环状态 i=9 while i>2:#打印9到5 if i==4: continue i=i-1 #continue小弟语句不会执行 print(i) i=i-1# 使得条件为假 # 打印出9到3,无4 i=9 while i>2:#打印9到5 if i==4: i=i-1 #跳出continue循环的条件 continue print(i) i=i-1# 使得条件为假 i=9 while i>2:#打印9到5 if i==4: i=i-1 #跳出continue循环的条件 continue print(i) i=i-1# 使得条件为假 # break语句跳出循环 #打印9到5 i=9 while i>2:#打印9到5 if i==4: break#跳出循环 print(i) i=i-1# 使得条件为假 #打印9到5与hello i=9 while i>2:#打印9到5 if i==4: break#跳出循环 print(i) i=i-1# 使得条件为假 print('hello') while i>2:#打印9到5,条件变量值需要优先设置 if i==4: break#跳出循环 print(i) i=i-1# 使得条件为假 print('hello')
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Python爬虫:Request Payload和Form Data的简单区别说明
浅谈Python中threading join和setDaemon用法及区别说明
Python3-异步进程回调函数(callback())介绍
python继承threading.Thread实现有返回值的子类实例
Python中使用threading.Event协调线程的运行详解
网友评论