01_python学习记录
一、第一个程序
cd change directory
dir 查看当前文件列表
print("hello world!")
二、变量的作用
存储程序运算结果,方便日后调用;
三、变量的命名规则
1、要具有描述性
2、只能以下划线、数字、字母组成;不可以是特色字符(#*《》),
3、不能以中文为变量名
4、不能以数字开头、
5、保留字符不能被使用
四、常量
不变的量
pie=3.1415926
在py里面所有的变量都是可变的,所以用全部大写的变量名来代表次变量为常量。
五、变量的重新赋值
name="chenfei"
name2=name
print(name,name2)
name="jake"
print(name,name2)
六、编码
unicode 万国码 支持所有国家和地区的编码
2**16=65536 存一个字符,统一占用2个字节
UTF-8,是对Unicode编码的压缩和优化,他不再使用最少使用2个字节,而是将所有的字符和符号进行分类:ascii码中的内容用1个字节保存、欧洲的字符用2个字节保存,东亚的字符用3个字节保存...
UTF-8(8-bit Unicode Transformation Format)是一种针对Unicode的可变长度字符编码,又称万国码。由Ken Thompson于1992年创建。现在已经标准化为RFC 3629。UTF-8用1到6个字节编码Unicode字符。用在网页上可以统一页面显示中文简体繁体及其它语言(如英文,日文,韩文)。
七、 中文声明(python2系列需要)
#!-*- codint:utf-8 -*-
#coding:utf-8
八、中文输出
msg="我爱北京天安门?"
print(msg)
九、代码注释
'''print(msg)
print(msg)''' 多行注释
#print(msg) 单行注释
十、用户输入
death_age=80
name=input("your name:")
age=input("your age:")
print("You name:",name)
print("You can still live for",str(death_age-int(age)),"years。。。。")
print("You can still live for",death_age-int(age),"years。。。。")
print("You can still live for" + str(death_age-int(age)) +"years。。。。")
十一、第一个可以判断的程序
age_of_princal=56
guess_age=int( input(">>:"))
if guess_age==age_of_princal:
print("Yes,you got it..")
else:
print("NO,it's wrong")
十二、缩进
视图,显示空格与制表符
设置—首选项—语言—制表符设置-“替换为空格”
十三、多分支if
age_of_princal=56
guess_age=int( input(">>:"))
if guess_age==age_of_princal:
print("Yes,you got it..")
elif guess_age > age_of_princal:
print("should try samller..")
else:
print("try bigger")
score=int(input("score:"))
if score > 90:
print("A")
elif score > 80:
print("B")
elif score > 60:
print("C")
else:
print("滚")
作业:
编写登录接口
输入用户名密码
认证成功后显示欢迎信息
输错三次后锁定
未实现锁定状态记忆,待学习
user="chenfei"
password="123456"
import getpass
print("欢迎登录pyhton系统")
count = 0
while count < 3:
print("请输入用户名")
user2=input(">>>:")
print("请输入密码")
password2=getpass.getpass(">>>:")
if user2 == user and password2==password:
print("恭喜登录成功")
elif user2 != user or password2!=password:
print("用户名或密码输入错误,请重新输入")
count+=1
else:
print("您已输入错误超过3次,账户已锁定")