第四章 第一节 python基础
填写上机记录:日期:9.28 班级: 节次:5 内容:python基础
下课时,整理好座椅后,再离开。
1、数据类型:
数字(整数(int)、float、str)、(运算符:“+-*/ ** //) and or not 看课本:70页 > < == 列表、元组、字典、集合
l 列表实例:
student=[ ]
for i in range(10):
x=input('请输入学生姓名')
student.append(x)
添加完成后,显示student列表
新学生来了:student.insert(0,'夏雪美') #在指定位置插入
学生转学:student.pop(0) 移除的时索引
索引的确定方法: student.index('崔翠萍')
student.pop( ) 移除的时索引
学生按姓名排序:
倒序:student.sort()
升序:student.sort(reverse=True)
l 元组实例:
names = ("崔翠萍","张文斌","李慧")
print(names[0],names[1],names[2])
print (names)
不允许更改
Names.append()出错
Python 元组Tuple 相对于数组List的优势
安全共享
元组的好处之一就在于这里,一旦三个关键词被设定为元组,则再也无法更改。非常适合用于固定关键词在对象之间的共享。
l 字典实例
每个键只能对应一个项
student= {'name':'崔翠萍','age':38,'schoolname':'邹平市第一中学'}
student['name']
for item in student:
print(item)
for i in student.items()
print(item)
以元组的形