这里所说的公共操作指的是之前学过的序列基本上都支持的一些操作,主要分成三大块来讲解,第一块是运算符;第二块是公共方法;第三块是容器类型转换。

一、运算符

二、运算符加号 +(合并)
代码体验:

  1. str1 = 'aaa'
  2. str2 = 'bbb'
  3. list1 = [1, 2]
  4. list2 = [3, 4]
  5. tuple1 = (10, 20)
  6. tuple2 = (30, 40)
  7. # 字符串合并
  8. print(str1 + str2)
  9. # 列表合并
  10. print(list1 + list2)
  11. # 元组合并
  12. print(tuple1 + tuple2)

执行结果:

三、运算符乘号 *(复制)
代码体验:

  1. str1 = 'aaa'
  2. list1 = [1, 2]
  3. tuple1 = ('hello',)
  4. # 字符串复制
  5. print(str1 * 3)
  6. # 列表复制
  7. print(list1 * 5)
  8. # 元组复制
  9. print(tuple1 * 5)

执行结果:

四、判断数据是否存在(in 、 not in)
代码体验:

  1. str1 = 'abcd'
  2. list1 = [1, 2, 3, 4]
  3. tuple1 = (10, 20, 30, 40)
  4. dict1 = {'name': 'Python自学网', 'age': 30}
  5. # 字符串 - 字符b是否存在
  6. print('a' in str1) # True
  7. print('a' not in str1) # False
  8. # 列表 - 数据2是否存在
  9. print(2 in list1) # True
  10. print(2 not in list1) # False
  11. # 元组 - 数据20是否存在
  12. print(20 in tuple1) # True
  13. print(20 not in tuple1) # False
  14. # 字典 - 数据age是否存在
  15. print('age' in dict1) # True
  16. print('age' not in dict1) # False
  17. print('age' in dict1.keys()) # True
  18. print('age' in dict1.values()) # False

执行结果:

更多相关文章

  1. 将服务器端字符读取至android的文本控件,换行符变成了黑方块的原
  2. .net平台借助第三方推送服务在推送Android消息(极光推送)
  3. Android常用的intent action汇总
  4. 字符串学习
  5. 实例演示字符串函数
  6. MySQL主从复制配置
  7. php中.=什么意思
  8. Android(安卓)KTX举例
  9. js-基础(六)字符串和数组的api

随机推荐

  1. Centos设置开机启动Apache和Mysql[总结]
  2. MySQL添加外键错误1215
  3. 如何在执行bash查询时,获得受影响的行数?
  4. SQL查询结果区分大小写
  5. 关于淘宝的数据库系统
  6. 如何将空值传递给外键字段?
  7. python3.x的torndb使用记录(发现网上没有
  8. mysql日志文件过大导致磁盘空间不够的问
  9. 正确使用MySQL JDBC setFetchSize()方法
  10. 使用IP地址方法登录MySQL数据库Can't