博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python-序列-str list tuple
阅读量:4700 次
发布时间:2019-06-09

本文共 997 字,大约阅读时间需要 3 分钟。

序列 有序数列

  str tupe list
  str tupe 不可变
  list 可变
序列(str list tuple) 每个元素都会有个序号(0开始计数)
  1. 知索引取单个确定类型 [index]
  2. 知值取索引 .index
  3. 切片 [start: end: step], 负数(-1开始计数)从序列倒数第几个取值,空表示从左到右取到最后
  4. 取序列的长度 len
  5. 求数列中最大最小 max min 非数字类型转化为ascii码对应的数字进行比较
  6. 序列求和 sum
  7. 序列拼接 +
  8. 序列拷贝次数 *
  9. 统计元素 .count
  10. 删除 del

str_list = ["hai", "hello", "wei", "here", 1, 2, 3]print(str_list[1])print(str_list.index("hai"))print(str_list[:1])print(str_list[::2])print(len(str_list))print(max(str_list[:4]))print(min(str_list[4:]))print(sum(str_list[4:]))print(str_list + [8, "aliYun"])print(str_list * 2)print(str_list.count("hai"))del str_list[0]print(str_list)

 

判断单个元素是否在这个序列中

  1. 是否在 in
  2. 是否不在 not in

str_elements = "sjidanntlsnakn "print(" " in str_elements)print("sji" not in str_elements)

 

序列类分类

  1. 容器序列 list tupe deque

  2. 扁平序列 str bytes bytearray array.array
  3. 可变序列 list deque bytearray array
  4. 不可变 str tuple bytes
  # 数组中放同一类数据

  

 

转载于:https://www.cnblogs.com/2bjiujiu/p/9061927.html

你可能感兴趣的文章
[Angular 2] Exposing component properties to the template
查看>>
C++学习笔记之STL标准库(六)set/multiset 关联容器
查看>>
2017-08-22 随笔
查看>>
KMP瞎扯一下
查看>>
div盒子中子元素(子元素可能是盒子, 图片) 中居中的三种方法
查看>>
【CF653G】Move by Prime 组合数
查看>>
spring mvc+mybatis+sql server简单配置
查看>>
bzoj1664:参加节日庆祝
查看>>
个人博客06
查看>>
[Usaco2005 dec]Layout
查看>>
ChatSecure
查看>>
中国剩余定理学习笔记
查看>>
深度学习中优化【Normalization】
查看>>
POJ2309BST(树状数组)
查看>>
洛谷P2114 起床困难综合症【位运算】【贪心】
查看>>
Ubuntu+caffe训练cifar-10数据集
查看>>
net 把指定 URI 的资源下载到本地
查看>>
招投标专家库
查看>>
OJ-2:区间问题【九度1554】
查看>>
NSURLSession详解
查看>>