练习一
创建变量a,b,c,d,e,f,分别存储任意数值、字符串、元组、列表、集合、字典,并通过type查看,将对应结果与字符串一起输出(5种方法),并写出一定的注释
print("a的类型为:" + str(type(a))) #打印a
print("b的类型为:%s"%(type(b))) #打印b
print(f"c的类型为:{type(c)}") #打印c
print("d的类型为:{0}".format(type(d))) #打印d
print("e的类型为:",type(e)) #打印e
print("f的类型为:",type(f)) #打印f
注意:
①print("b的类型为:%s"%(type(b))) #“”与%之间无任何符号
②print("e的类型为:",type(e)) #中间有逗号
③print(f"c的类型为:{type(c)}") #print括号开头有f
④print("d的类型为:{0}".format(type(d))) #中间有英文运算符中的句号,并且注意format的拼写
练习二
尝试将字符串“今天天气不错”转化成列表类型
x1=”今天天气不错”;list(x1)
练习三
变量a勇于接受一个字符串,可能接受“1”,也有可能接受“1.1”,
尝试用一个统一的式子转化成数值类型
a="1"
print(eval(a))
a='1.1'
print(eval(a))