print(type(5)) # 用type这个方法看用户输入的类型(用户输入 5 这是整数)
print(type(5.0)) # 用type这个方法看用户输入的类型(用户输入 5.0 这是浮点数)
print(type('qytang')) # 用type这个方法看用户输入的类型(用户输入 'qytang' 这是字符串)
print(type(print)) # 用type这个方法看print类型
lst = [7, -7, 2, 3, 2] # 给lst赋值列表
print(len(lst)) # 查看lst列表的长度
print(lst + lst) # 两个列表的拼接
print(lst * 2) # 打印2倍的lst列表
lst[2] = "dog" # 将lst列表的第三个位置替换或修改为'dog'字符串
print(lst) # 打印新lst
lst[2] = lst # 将原lst赋值给lst中的第三位
print(lst)
结果:
"D:\Program Files (x86)\Python35\python.exe" "D:/Program Files (x86)/Python35/wyw1/a.py"
<class 'int'>
<class 'float'>
<class 'str'>
<class 'builtin_function_or_method'>
5
[7, -7, 2, 3, 2, 7, -7, 2, 3, 2]
[7, -7, 2, 3, 2, 7, -7, 2, 3, 2]
[7, -7, 'dog', 3, 2]
[7, -7, [...], 3, 2]
Process finished with exit code 0
python:type语句与列表操作函数
最新推荐文章于 2024-06-29 12:49:26 发布