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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值