学习 D3

字符串的查找与检查

index方法

index 是一种方法 不是函数

在字符串中找到所要求的 最低索引 (最近的 最左边) 返回索引的值

找不到就报错

例:

str = ‘asd’

str.index(‘a’)

输出结果 0

find 和 rfind 方法

find 从左往右找 返回先找到的索引值 找不到 返回-1

def find(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
    """
    S.find(sub[, start[, end]]) -> int
    
    Return the lowest index in S where substring sub is found,
    such that sub is contained within S[start:end].  Optional
    arguments start and end are interpreted as in slice notation.
    
    Return -1 on failure.
    """
    return 0

rfind 从左往右 返回最高找到的 索引值 找不到 返回 -1

def rfind(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
    """
    B.rfind(sub[, start[, end]]) -> int
    
    Return the highest index in B where subsection sub is found,
    such that sub is contained within B[start,end].  Optional
    arguments start and end are interpreted as in slice notation.
    
    Return -1 on failure.
    """
    return 0

count 方法

返回所查找的 在字符串中出现的次数 找不到 返回 0

def count(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
    """
    B.count(sub[, start[, end]]) -> int
    
    Return the number of non-overlapping occurrences of subsection sub in
    bytes B[start:end].  Optional arguments start and end are interpreted
    as in slice notation.
    """
    return 0

其他方法

判断是否全由数字组成的方法isdigit 
endswith 判断是否以指定的结尾
capitalize 
istitle
title
endswith
isalpha
isdecimal 是否是小数
islower
replace
strip 删除字符串首尾空格  若给出指定字符 就删除指定字符 

title capitalize upper 方法 的比较

列表

1 表达形式

list1 = []
2 列表元素可以是不同的数据类型

3 列表可以 嵌套 例 : list1 = [1,2,[1,2,3,‘aa’]]
4 提取列表中的列表 例:
list1 = [1,2,3,[‘a’,‘b’,‘c’]]
例如 取 b

for i in list1[3][1]:
print(i)

列表的切片

用法

可迭代对象

就是每个元素都能提取出来就是可迭代对象

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值