python笔记 <head> 打印命令 print ----print 打印命令------ 定义变量格式 XXX = ("XXX") 引用格式1:print(XXX) 引用格式2:print(‘输入任何内容加引号‘,XXX) 打印字符类型 print(type(XXX)) 实验 name = "Hello World!" print(name) print(‘my name is‘,name) 返回结果 Hello World! my name is Hello World! ------------------------------ </head> <head> 交互式输入 input AAA = input("AAA:") BBB = input("BBB:") print(AAA,BBB) </head> <head> 格式打印 #%s (全拼string) (验证字符) #%d 整数 (验证整数)检测验证数据类型 错误则报错 #%f 浮点数 .format 格式2、3 指定{}中内容=某个变量 ---------格式打印1------------- AAA = ‘111‘ BBB = ‘222‘ CCC = ‘333‘ test = ‘‘‘ %s %s %s ‘‘‘%(AAA,BBB,CCC) print(test) 实验 name = ‘gaoliandi‘ ago = ‘30‘ work = ‘IT‘ info = ‘‘‘ %s %s %s ‘‘‘%(name,ago,work) print(info) --------格式打印2-------------- AAA = ‘111‘ BBB = ‘222‘ CCC = ‘333‘ test = ‘‘‘ {aaa} {bbb} {ccc} ‘‘‘.format(aaa=AAA, bbb=BBB, ccc=CCC) print(test) --------格式打印3-------------- AAA = ‘111‘ BBB = ‘222‘ CCC = ‘333‘ test = ‘‘‘ {0} {1} {2} ‘‘‘.format(AAA,BBB,CCC) print(test) </head> <head> 字符转换 int str int(XXX) 转化整数 str(XXX) 转化字符 </head> <head> 利用交互式输入账户密码(加密) 判断账户密码是否正确 笔记 import getpass 调用getpass模块 import加载模块命令 模板 password = getpass.getpass("password:") if (判断条件,不缩进) 子命令行必须缩进 else: (否则执行条件,不缩进) 子命令行必须缩进 实验 import getpass _username = "gaoliandi" _password = "abc123" username = input("username:") password = getpass.getpass("password:") if _username == username and _password == password: print(‘Welcone user {name} login...‘.format(name=username)) else: print("Invalid username or password!") </head> <head> </head> <head> </head> <head> </head> <head> </head> <head> </head> <head> </head> <head> </head> <head> </head> <head> </head> <head> </head>
时间: 2024-10-10 09:31:49