格式化输出:
# name = input('请输入姓名')
# age = input('请输入年龄')
# hobby = input('请输入爱好')
# msg = '我的姓名是' + name + '我今年' + age + '我的爱好是' + hobby
# print(msg)
# 字符串的拼接可以制作一个公共字符串模板,让某些位置变成动态的。
"""
msg = '''------------ info of Alex Li -----------
Name : Alex Li
Age : 73
job : sbboss
Hobby: laddy_boy
------------- end -----------------'''
msg1 = '''------------ info of 杨苏婷 -----------
Name : 杨苏婷
Age : 18
job : student
Hobbie: movie
------------- end -----------------'''
"""
# name = input('请输入姓名:')
# age = input('请输入年龄:')
# job = input('请输入工作:')
# hobby = input('请输入爱好:')
# '''
# 这样做很麻烦,用格式化输出
# s1 = '------------ info of '+ name + ' -----------\n'
# s2 = 'Name : ' + name + '\n'
# '''
# # % 占位符 s:字符串类型 d:数字 i:数字 # r 原形毕露
# msg = '''------------ info of %s -----------
# Name : %s
# Age : %d
# job : %s
# Hobbie: %s
# ------------- end -----------------''' % (name,name,int(age),job,hobby)
# print(msg)
# 格式化输出 如果你只是想要表示百分号%,而不是占位符。
# msg = '我叫%s,今年%s岁,学习进度为0.5%%' % ('高航', 40)
# print(msg)
while循环
# 1,初识循环
# while True:
# print('海草')
# print('女儿情')
# print('二泉映月')
# print('牧马城市')
# 如何终止循环
'''
1,改变条件。
2,break
3,调用系统命令:quit() exit() (不建议使用)
'''
# flag = True
# while flag:
# print('海草')
# print('女儿情')
# flag = False
# print(111)
# print(222)
# 四个都打印
# 从 1 ~ 100 利用while循环
# 计数器的概念
# count = 1
# flag = True
# while flag:
# print(count)
# count = count + 1
# if count == 101:
# flag = False
# count = 1
# while count < 101:
# print(count)
# count = count + 1
# count = 1
# count = 2
# count = 3
# print(count)
# count = 1
# count = count + 1
# count = count + 1
# print(count)
# while break continue
# break:循环中遇到break 直接退出循环,
# print(111)
# while True:
# print(222)
# print(333)
# break
# print(555)
# print(666)
# 打印 1~100 所有的偶数。
# 方法一
# count = 2
# while count < 101:
# print(count)
# count = count + 2
# count = 2
# while True:
# if count % 2 == 0:
# print(count)
# count = count + 1
# if count > 100:
# break
# count = 2
# while count < 101:
# if count % 2 == 0:
# print(count)
# count = count + 1
# continue
# 结束本次循环,继续下一次循环
# while True:
# if
# print(111)
# print(222)
# continue
# print(333)
# 计算 1 + 2 + 3 + 4 + 5 + ...100 结果
#
# s = 0
# count = 1
# while count < 101:
# s = s + count
# count = count + 1
# print(s)
# 固定搭配: 循环只要被break打断,则就不会执行else的程序。
#while else
# count = 1
# while count < 5:
# count = count + 1
# print(count)
# else:
# print(666)
count = 1
while count < 5:
count = count + 1
print(count)
if count == 10:
break
else:
print(666)
运算符
# print(2**3)
# 逻辑运算
# 优先级
# ()>not>and> or,同一个优先级从左至右一次计算。
# 1,运算符两边全部是比较运算。
# print(1 > 2 or 3 < 4 and 1 < 2 or 3 > 7)
# print(1 > 2 or True or 3 > 7)
# print(2 > 1 and 3 < 4 or 4 > 5 and 2 < 1)
# print(1 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 <10)
# 2 ,运算符两边全部是数字。
'''
x or y if x is True, return x,else y
'''
# print(1 or 3)
# print(2 or 3)
# print(10 or 3)
# print(0 or 3)
# print(-3 or 3)
# print(1 and 3)
# print(-1 and 3)
# print(0 and 3)
#int bool
# int ---> bool 非0即True
# print(bool(-2))
# print(bool(2))
# print(bool(0))
# bool ---> int True 1 Flase 0
# print(int(True))
# 面试题:
# print(1 and 3 or 4 and 5)
# 第三种,思考题:
# print(1 > 2 or 3 and 4 < 5 or 7)
# 成员运算:
# s = 'alex 中'
# s1 = 'a'
s = 'alexsb'
# print('a' in s)
# print('al' in s)
# print('ae' in s) # False
# print('alex' in s) # False
# print('alexsb' in s) # False
# print('a' not in s)
# print(2**16)
print(2**32)
作业
# count = 66
# # while True:
# # x = int(input('请输入你的年龄'))
# # if x < count:
# # print('猜测结果小了')
# # elif x>count:
# # print('猜测结果大了')
# # else:
# # print('正确')
# # break
# import random
# count = random.randint(1,100)
# a = 0
# print(count)
# while a < 3:
# x = int(input('请输入你的数字'))
# #while x != count:
# if x < count:
# print('猜测结果小了')
# else:
# print('猜测结果大了')
# a +=1
# if a == 3:
# print('重新开始')
# break
# else:
# print('正确')
# import random
# count = random.randint(1,100)
# a = 0
# print(count)
# while a < 3:
# x = int(input('请输入你的数字'))
# while x != count:
# if x < count:
# print('猜测结果小了')
# break
# else:
# print('猜测结果大了')
# break
# a +=1
# if a == 3:
# print('重新开始')
# break
# else:
# print('正确')
# break
# count=0
# while count < 10:
# count += 1
# print(count)
# count = 0
# a = 0
# while a < 100:
# a += 1
# count += a
# print(count)
# count = 0
# while count < 100:
# if count % 2 == 1:
# print(count)
# count+=1
# count = 1
# flag = True
# while flag:
# if count % 2 == 0:
# print(count)
# count += 1
# if count == 101:
# flag = False
# count1 = -1
# count2 = 0
# count3 = 0
# count4 = 0
# while count1 < 100:
# count1 += 2
# count2 += count1
# count3 += -2
# count4 += count3
# else:
# print(count2+count4)
# a=-1
# b=0
# while a<100:
# a=a+2
# b=b+a
# else:
# print(b)
# count=0
# name = 'Oldboy'
# key = 123456
# while count<3:
# Username = input('请输入你的用户名')
# Password = input('请输入密码')
# msg = '用户名为%s,密码为%s,错误%d次' % (Username, Password,count)
# count += 1
# if Username==name and Password==key:
# print('登陆成功')
# break
# else :
# print(msg)
# else:
# print('请退出')
# if __name__=='__main__':
# li=[1,2,3,4,5] #列表本身不包含数据1,2,3,4,5,而是包含变量:li[0] li[1] li[2] li[3] li[4]
# first=li[0] #拷贝列表,也不会有数据对象的复制,而是创建新的变量引用
# del li[0]
# print(li) #输出[2, 3, 4, 5]
# print(first) #输出 1
# a=5
# b=2
# c=a/b
# print(type(c))