标签:后缀名 关键字 time inpu int break 一个 用法 nal
ps:数字不能开头;不能是关键字;最好不要和python内置的东西重复***
关键字:[‘and‘, ‘as‘, ‘assert‘, ‘break‘, ‘class‘, ‘continue‘, ‘def‘, ‘del‘, ‘elif‘, ‘else‘, ‘except‘, ‘exec‘, ‘finally‘, ‘for‘, ‘from‘, ‘global‘, ‘if‘, ‘import‘, ‘in‘, ‘is‘, ‘lambda‘, ‘not‘, ‘or‘, ‘pass‘, ‘print‘, ‘raise‘, ‘return‘, ‘try‘, ‘while‘, ‘with‘, ‘yield‘]
例如:
1 a1 = "欢迎你的到来!" #变量 2 print(a1) 3 =========== 4 print("欢迎你的到来")
1 if 条件: 2 print("Ok") 3 else: 4 print("Error")
1 if 1=1: 2 if 2=2: 3 print("hello") 4 print("hello2") 5 else: 6 print("error") 7 else: 8 print("error2")
1 inp = input(‘请输入你的会员级别:‘) 2 if inp == "高级会员": 3 print(‘欢迎高级会员‘) 4 elif inp == "铂金会员": 5 print(‘欢迎铂金会员‘) 6 elif inp == "钻石会员": 7 print(‘欢迎钻石会员‘) 8 else: 9 print(‘欢迎普通会员‘) 10 print(‘欢迎光临本店......‘)
知识点:if基本语句 else
补充:pass 代指空代码,无意义;仅仅用于表示代码块。如果python不想输出任何东西,写pass直接跳过不输出任何语句。
1 name = "alex" 2 name = ‘alex‘ 3 name = """alex""" 4 name = ‘‘‘alex‘‘‘
字符串使用方法:
1 加法: 2 n1 = ‘alex‘ 3 n2 = ‘tom‘ 4 n3 = n1+n2 5 print(n3) #输出效果alextom 6 7 乘法: 8 n1 = ‘alex‘ 9 n2 = n1*10 10 print(n2) #输出效果alexalexalexalexalexalexalexalexalexalex
1 eg: 2 age = 19 3 4 加、减、乘、除、次方、取余: 5 a1 = 10 6 a2 = 20 7 a3 = a1 + a2 8 a3 = a1 - a2 9 a3 = a1 * a2 10 a3 = 100 / 10 11 a3 = 3**4 #获取3的4次方 12 a3 = 39 % 8 #获取39除以8得到的余数 13 a3 = 39 // 8 #获取39除以8得到的商 14 15 判断奇数、偶数; 16 a = 15 17 temp = a % 2 18 if temp == 0: 19 print(‘偶数‘) 20 else: 21 print(‘奇数‘)
1 import time 2 while 1 == 1: 3 print(‘ok‘,time.time())
1 import time 2 count = 0 3 while count < 10: 4 print(count) 5 #count = 100 6 count = count + 1 7 print(123)
ps:
1.while ....else 循环
2.continue 终止当前循环,开始下一次循环; break 终止所以循环
标签:后缀名 关键字 time inpu int break 一个 用法 nal
原文地址:https://www.cnblogs.com/Tang-Yuan/p/9242526.html