栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python 笔记4 公共方法

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python 笔记4 公共方法

元组,列表,字典 公共方法

公共方法1: 

# +  *

# +(合并) 字符串 列表 元组
print('hello'+'python')  #hellopython
print([1,2,3]+[4,5,6])   #[1, 2, 3, 4, 5, 6]
print((1,2,3)+(4,5,6))   #(1, 2, 3, 4, 5, 6)

# *(复制) 字符串 列表 元组
print('='*50)    #==================================================
print([1,2]*5)   #[1, 2, 1, 2, 1, 2, 1, 2, 1, 2]
print((1,2)*5)   #(1, 2, 1, 2, 1, 2, 1, 2, 1, 2)

公共方法2:

# in(测试数据是否在变量里) not in
# in   not in  字符串 列表 元组 字典
print('hello'in 'hello python')   #True
print(12 in [1,2,3])    #False
print(3 in (1,2,3))     #True

#注意. in在字典操作时,判断的是字典的key(键)
dict01 ={'name':'张三','age':18}
print(18 in dict01)  #False
print('name' in dict01)  #True
print('age' in dict01)  #True
print('age' not in dict01)  #False

公共方法3:

#内置函数

# len() 计算容器中元素的个数
# max() 输出容器中元素最大值,字典输出key
# min() 输出容器中元素最小值,字典输出key

# del() 删除变量
a=[1,2,3]
del a[1]
print(a)  #[1, 3]
del a
print(a)  #NameError: name 'a' is not defined

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/445776.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号