2019.9.10作业
-
简述Python的五大数据类型的作用、定义方式、使用方法:
-
数字类型
整型(int)
作用:表示整数
定义方式:a = 1或a = int(1)
使用方法:+ - * / ** // %
浮点型(float)
作用:表示小数
定义方式:a = 1.123或a = float(1.123)
使用方法:+ - * / ** // %
-
字符串类型
作用:描述一下东西
定义方式:'' "" '''''' """""" 或s = str('')
使用方法:+ *
-
列表
作用:描述一连串东西的表格
定义方式:ls = [] 或ls = list(iterable)
使用方法:+ 索引
-
字典
作用:定key查找一系列数据
定义方式:dic = {key1:value1,key2:value2,......}
使用方法:按key取值
-
布尔型
作用:对特定代码进行判断True False
定义方式:int型子类
使用方法:判断
-
-
一行代码实现下述代码实现的功能:
x = 10
y = 10
z = 10
x = y = z = 10
- 写出两种交换x、y值的方式:
x = 10
y = 20
z = x
x = y
y = z
x,y = y,x
- 一行代码取出
nick
的第2、3个爱好:
nick_info_dict = {
'name':'nick',
'age':'18',
'height':180,
'weight':140,
'hobby_list':['read','run','music','code'],
}
print(nick_info_dict['hobby_list'][1],nick_info_dict['hobby_list'][2])
- 使用格式化输出的三种方式实现以下输出(name换成自己的名字,既得修改身高体重,不要厚颜无耻)
name = 'Nick'
height = 180
weight = 140
# "My name is 'Nick', my height is 180, my weight is 140"
占位符
name = 'Agsol'
height = 226
weight = 160
print("My name is '%s', my height is %d, my weight is %d"% (name,height,weight))
.format
name = 'Agsol'
height = 226
weight = 160
print("My name is '{}', my height is {}, my weight is {}".format(name,height,weight))
f-string
name = 'Agsol'
height = 226
weight = 160
print("My name is '{}', my height is {}, my weight is {}".format(name,height,weight))