1.print(a == c) #比较的时候,除了比较两边的值,还会比较变量的数据类型;
布尔值bool只包括True 和 False,可用于条件判断;
and x and y 布尔“与” 如果x为false,x and y 直接返回false不会计算y,否则返回y的计算值
print(not a) 布尔非
2.tobnine 自动补全代码 单按Tab键
3.复数complex 前面是数字,后面是字母;None:暂时不确定储存什么值,就赋None值,相当于占位;当使用时再重新赋值
4.字符串 :放在单引号或者双引号里面的任何字符
5.list列表 :可以储存不同类型的多个值
nameList = ['杨浩亮','张三','李四','王五',10,True,2+1j]
print(nameList)
print(type(nameList))
6.字典和list一样也可以储存不同类型的多个值,但格式有所不同:{key:value,key2:value2}
7.将字典数据添加到列表中,需要用到列表添加函数append
stu_list = []
stu = {'no':16,'name':'张三','age':18,'sex':'女'}
stu2 ={'no':18,'name':'李四','age':16,'sex':'男'}
stu_list.append(stu)
stu_list.append(stu2)
print(stu_list)
8.元组格式('元素','元素2'.......),其储存的值在程序运行时不能修改
9.集合有两种创建方式
- 1.set()函数
- 2.{}创建
res = set([1,3,5,7])
print(res)
print(type(res))
res2 = {1,3,5,7}
print(type(res2))
10.当unexpected incent:缩进有问题
可使用pycharm自动调整格式
- 选中代码,最上面工具栏找Code,点Reformat Code
- Ctrl + Alt + L(与QQ热键有冲突)
11.输入
name = input('请输入你的登录账户:')
name = int(name)
#name = float(name)(将结果转化成浮点类型)
#name = int(input('请输入你的登录账户:')
print(name)
print(type(name))#获变量的数据类型
12.if条件语句:
- 单分支条件语句,条件满足执行,反之不执行
age = 17
if age > 18:
print('恭喜成年')
- 双分支条件语句 条件为真执行if后面代码块,条件为假执行else后面代码
age = input('请输入你的年龄:')
age = int(age)
if age >= 18:
print('成年了')
else:
print('还未成年')
- if 逻辑运算符 or&and
color = input('你白吗?') money = float(input('你富吗?')) # 输入数字金额 beautiful = input('你美吗?') if color == '白' and money >= 10000000.50 and beautiful == '美': print('白富美') else: print('..')
- if elif.....
score = int(input('请输入你的考试成绩')) if score > 85 and score <= 100: print('A') elif score > 75 and score <= 85: print('B') elif score > 60 and score <= 75: print('C') else: print('D')