a = 20;
print(type(a))#数字类
mag = """my name is alex
i am from Fujian""";
#多引号可以多行使用
a = ["Alex","Jack","Rain","WuSir","BlackGirl"]
a[4] = "白雪公主";
a.insert(4,"天鹅")#插入元素
a.append("Alex")#追加
del a[3];#删除元素
a.remove("WuSir")#删除元素,优先查找到的先删除
print("Rain" in a)#查找Rain元素是否在数组里
#逻辑运算符
#and,or(并且,或者)
a1 = 10
a2 = 20
print(a1 < 20 and a1 <= a2)#并且,两个条件都要符合即可
print(a1 < 20 or 1 <= a2)#或者,两个条件一个符合即可
#input输入框
a4 = input("1:")
a5 = input("2:")
print(int(a4) * int(a5))
#【注】:输入的内容都是属于字符串,我们要将字符串转为 int(数字类型)才可以进行运算
#变量在字符里的使用
name = input("name:")
age = input("age:")
mag2 = f"""
--------------- info of {name} -------------------
Name : {name}
age : {age}
# --------------- End--------------------------------
""";
print(mag2)
#在字符串前面加上 f 即可使用外部变量
#for循环
for i in range(0,100):
if i % 2 == 0:
print (f"{i} is 是偶数")
else:
print(f"{i} is 是奇数")
#练习(一栋房子共六层,每层8间房间,在循环到第三层的时候跳过,到第四层的时候打印 在装修 并且循环出每一层的层数和每层的房间号)
for i in range(1,6):
if i == 3:
continue
for a in range(8):
if i == 4 and a == 4:
print("装修中")
break
else:
print(f"这是第L{i}层,这是{i}0{a}号房间")
#字符查找
a = "Alex"
print(a.center(50,"-"))# -----------------------Alex-----------------------
print(a.count("l"))# 查找l
print(a.endswith("A"))# 判断结尾
print(a.startswith("A"))# 判断开头
print(a.find("l")) #字符查找,如果查找到就返回字符的索引
a2 = ["alex","black","blue"]
print('-'.join(a2))#连接符
#按分数放入指定的列表
a3 = [['小李',82],['小晓',90],['小薇',60]]
a4 = [
[], #90
[], #75
[], #60
]
for i in a3:
if i[1] >= 90:
a4[0].append(i)
elif i[1] >= 75:
a4[1].append(i)
else:
a4[2].append(i)
print(a4)
#字典的 增,删,查
a5 ={
"Alex" :[20,"CEO",66000],
"白雪公主" : [20,"行政",4000],
}
print("白雪公主" in a5)#查找字典里的key
a5 ["姑娘"] = [20,"讲师",4000] #加入字典
a5.pop("姑娘")#删除指定的key
del a5["姑娘"]#通用 删除指定的key
print(a5)