北信Python0906-第二天-作业
1.定义int类型, float类型,complex类型,str类型,None类型,bool类型,bytes类型,tuple类型的变量,并打印其类型, 使用显式定义,例如:1, 2.2
2.定义int类型, float类型,complex类型,str类型,None类型,bool类型,bytes类型,tuple类型的变量,并打印其类型, 使用类型()定义
3.定义一个空元组,定义一个嵌套元组:嵌套元组中的每个元组包含两个元素
4.使用上课教的方法去看:元组中有哪些操作方法
int_data = 1
print(int_data)
float_data = 2.2
print(float_data)
complex_data = 1 + 2j
print(complex_data)
str = 'c'
print(str)
None
print(None)
bool = True
print(bool)
bytes = b''
print(bytes)
tuple = (1,2,3)
print(tuple)
int_data = 1
print(int_data,type(int_data))
float_data = 2.2
print(float_data,type(float_data))
complex_data = 1 + 2j
print(complex_data,type(complex_data))
str = 'c'
print(str,type(str))
None
print(None,type(None))
bool = True
print(bool,type(bool))
bytes = b''
print(bytes,type(bytes))
tuple = (1,2,3)
print(tuple,type(tuple))
tuple = ((1,2.2),(3,4.4))
print(tuple,type(tuple))
运行结果:
1
2.2
(1+2j)
c
None
True
b''
(1, 2, 3)
1 <class 'int'>
2.2 <class 'float'>
(1+2j) <class 'complex'>
c <class 'str'>
None <class 'NoneType'>
True <class 'bool'>
b'' <class 'bytes'>
(1, 2, 3) <class 'tuple'>
((1, 2.2), (3, 4.4)) <class 'tuple'>
Process finished with exit code 0
有两个疑问:
1、定义数据类型:
None: 空类型, 其他语言中:null
None
print(None,type(None))
None <class ‘NoneType’>
其他打印出来都是直接整形(int)或者浮点(float),这个出现’NoneType’
2、
第三题不知道到底算成功了吗
定义一个空元组,定义一个嵌套元组:嵌套元组中的每个元组包含两个元素