Python环境安装
-安装解释器
-安装pycharm
Python数据类型
常用的数据类型
-数字、字符串、字典、列表、元组、集合
列表
代码示例
heroList = ['鲁班七号','安其拉','李白',"后羿",1]
print(heroList)
列表的相关操作:
# 1.访问列表中元素 列表名[索引]
print("英雄为:",heroList[1])
# 2.添加元素 append是在列表的末尾添加
heroList.append("鲁班大师")
print("添加后的列表:",heroList)
# 3.修改
heroList[4]="貂蝉"
print("修改后的列表:",heroList)
# 4.删除
del heroList[4]
Python中的变量
声明:不用声明变量的类型,不用写;
a = 100
交换两个变量
a = 100
b = 1000
a, b = b, a
print(a, b)
判断语句
格式
if 要判断的条件:
满足条件时要执行的事情
else:
不满足条件时要执行的事情
代码示例
age = input('请输入您的年龄')
# age = 3
# print(type(age))
age = int(age)
if age >= 18:
print("您已经",age,"岁了,恭喜你成年了,可以去网吧了")
else:
print('sorry,你还是个宝宝')