20191205-温故知新from20191203
上节课20191203复习:
1. 编程语言:高级(php,java, python,c#),低级-C C++
2. python种类:
javapython cpython c#python pypy9(经过的解释器不同),主要用cpython
3. 字节码 和机器码
4. python程序:
① 解释器,找到路径 c:/python35/python.exe d:\1.py
②cmd里可以直接写,但是没法保存
③文件形式:linux标出安装路径 #/usr/bin/u/ubv/a python 若python 1.py没用,但./1.py有用(必须加权限)
④编码 # -*- coding:utf-8 -*-(python3默认有,可不加)
↓两行编码必须写在文件头部:
#/usr/bin/u/ubv/a python
#-*- coidng:utf-8 -*-
unicode位数至少16位+(=至少2字节),1字节=8位,ascii一个字节表示
unicode浪费空间,utf8全球通用,没有用多少位表示位数,中文用3字节。
写代码最好用utf8(全球通用,utf8表示中文位3个字节),gbk专门适用中文(2个字节表示),
若utf8打开jdk时,位数少了8位,gbk读utf8,只读前16位的两个字节,可能遗漏信息。
python2乱码是终端的问题,windows默认gbk编码,若文件位utf8,则可能漏信息。
python3多了一次加工,python3的数据类型和python2不同!python3里面没有字符串类型,全是字节,python3没有unicode。
utf8的文件,python3读取文件会进unicode,万国码转换为jdk,可以读取。
python2对utf8的文件,不会转unicode。

内存里是unicode
字节和位的关系,1字节=8位
unicode16+ utf824位 gbk16位
⑤print("hello world")
⑥ inp=input('>>>')永远等待用户信息
p.s. input接受到的信息均为字符串类型,
>>> hello
inp ="hello"
>>> 10
inp="10"并未数字!
inp *10=10101010101010101010而不等于100
可以讲字符串转换成数字 new_inp=int(inp)下文也会提到
⑦变量名
字母,数字,下划线。不能数字开头,不能用关键字,不建议用python内置内容:sum,如果用报错。
⑧if条件语句:if 条件: elif else 可以嵌套,缩进表示代码块
⑨while循环 while条件:死循环,,,代码块执行完再回来while条件,条件不满足才跳出。
ps. while
count = 0
while count<10:
print(count)
count+=1
else: 这里的else不循环
print('else')
continue在while中不再循环以下内容
count = 0 while count<10: continue print(123) 此处的print123不会执行
count = 0 while count<10: count+=1 print(count) continue print(123) print('end')
另一个while语句中的内:break,停止所有循环!
continue终止当前循环,break终止所有循环。
----------------------------------------------------------------------------------------------
作业:用户登陆-三次机会重试
while 条件:
count = 0 while count < 3: user = input('>>>') password = input('>>>') if user=='lacojic'and password=='123': #注意不要遗漏结尾的冒号!!!! print('welcome!') print('begin to study') break #退出循环 else: print('wrong user or password') count+=1
浙公网安备 33010602011771号