计算字符串,字典,列表,元组的长度
如下:
a1='hello python'
print(len(a1))
#2、计算字典的长度,{}分割,键与值之间以冒号分割
dict={'w1':0.9,'B1':9.1}
print(len(dict))
#3、计算列表的长度
str={'1',99,8}
print(len(str))
#4、计算元组的长度,元组和列表很像,一个是中括号,一个是小括号
tuple=('3',99,8)
print(len(tuple))
结果如下:
12
2
3
3