input用法
用户输入: >>> name = input("请输入你的姓名") 请输入你的姓名lj >>> name 'lj' >>> 1234567
while True 的用法
my_age = 18 count=5 while True: age = int(input("请输入年龄")) if age == my_age: print("you are right!") break elif age > my_age: count -= 1 print("bigger,还有{}次输入机会".format(count)) elif age < my_age: count-=1 print("smaller,还有{}次输入机会".format(count)) continue
12345678910111213141516结果如下:C:Python36python3.exe C:/Users/Administrator/Desktop/01.py 请输入年龄1 smaller,还有4次输入机会 请输入年龄19 bigger,还有3次输入机会 请输入年龄20 bigger,还有2次输入机会 请输入年龄7 smaller,还有1次输入机会 请输入年龄18 you are right! Process finished with exit code 0 12345678910111213
位运算符用法:
for循环
for i in range(0,10): if i <5: continue print(i) C:Python36python3.exe C:/Users/Administrator/Desktop/01.py 5 6 7 8 9 1234567891011
break 和continue的区别 1
for i in range(0,10): if i >5: #break continue print(i) C:Python36python3.exe C:/Users/Administrator/Desktop/01.py 0 1 2 3 4 5 Process finished with exit code 0 for i in range(0,10): if i >5: break #continue print(i) C:Python36python3.exe C:/Users/Administrator/Desktop/01.py 0 1 2 3 4 5 Process finished with exit code 0 ************************************************** for i in range(0,10): if i <5: #break continue print(i) C:Python36python3.exe C:/Users/Administrator/Desktop/01.py 5 6 7 8 9 Process finished with exit code 0 for i in range(0,10): if i <5: break #continue print(i) C:Python36python3.exe C:/Users/Administrator/Desktop/01.py Process finished with exit code 0
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768字符串格式化输出
name = "Duke" print("i am %s"%name) 12
常用-----> 字符串 %s;整数 %d;浮点数%f
另一种实现方法之format()方法
print('Hi,{name},{message}'.format(name = 'Duke',message = 'i am in Chengdu')) 1
参考:https://www.cnblogs.com/huigebj/p/11298332.html
https://www.cnblogs.com/dukeidea/p/6362031.html