学习python第一天,老师讲的很多东西都是在C里面讲过。今天内容还算轻松,是基础知识部分:
1.编程语言的种类:
高级语言:Java,C#,C++,PHP,Go,ruby,,,,
低级语言:C,汇编
2.python的种类:
Javapython:把python写的代码交给Java解释器变成字节码再由字节码转换成机器码
C python:直接交给python解释器变成字节码转换成机器码
python python:直接给C,直接转换成机器码
3.python程序:
①终端:
全路径:C:\python3.5\python.exe D:\1.py
解释器:C:python3.5\python.exe
②文件型:
#/usr/bin/u/ubv/a python (头部)
python 1.py 不加权限
.\1.py 加权限
python2只支持全英文,其中输入中文会乱码
# -*-coding:utf8-*- (在头部)
4.编码:
ASCILL码:8位 0000 0000
unicade(万国码):至少16位 0000 0000 0000 0000+
utf8:有几位便是几位 (一个汉字三个字节)
GBK(中国码):专为中国人使用的编码,(一个汉字两个字节)
utf8 转换 unicode 转换 GBK (即utf8可以通过unicade与GBK想换转换)
5.print语句:
print(“ ”) 中间是字符串,输出的是字符串
6.input语句
input(“ ”) 中间是字符串 永远等待用户输入
eg: 字符串转换成数字 如果 inp=input("10")中的“10”是字符串,不是数字,要输出数字,可以写成 int(10) 或者 int(inp) , 即 int() 语句便是输出数字
7.变量名:字母,数字,下划线
不能数字开头,不能使用关键字,不能用python内置的东西(eg:sum() sum在python中可以直接使用的函数)
8.if语句
①基本语句
②嵌套
③缩进:表示一个代码块
9.while循环语句
while 条件:
。。。
print(“ ”)
① while里也有else
eg:
count=0
while count<10;
print(count)
count=count+1
else:
print(" ")
print(" ")
②continue语句和break语句
continue语句(终止当前循环,开始下一次循环)
count=0
while count<10:
count=count+1
continue #只执行到这一步
print(123) #永远不执行
print("end")
break语句(终止所有循环)
count=0
while count<10:
count=count+1
print(count)
break #直接跳出循环,直接执行print("end")
print("")
print("end")
input输入语句
以及几个实例(为了怕过来几天自己都忘了自己学了些啥,还是记录下来比较好)
#输出1,2,3,4,5,6,8,9,10 n=1 while n<11: if n==7: pass else: print(n) n=n+1 print("end")
#输出100以内的奇数 n=1 while n<101: if n%2==0: pass else: print(n) n=n+1 print("end")
#输出1-100的和 n=1 s=0 while n<101: s=s+n n=n+1 print(s)
#求1-2+3—4+,,,到99 n=1 s=0 while n<100: if n%2==1: s=s+n else: s=s-n n=n+1 print(s)
#用户登录(三次机会重试) count=0 while count<3: user_name=input("please enter your name: ") pwd=input("please enter your password:") if user_name=="yanchuanyou" and pwd=="123456": print("welcome to login") else: print("the user_name or password is wrong") count=count+1