python常用方法-变量处理

1.字符转ascii数字

ord (字符) = ascii表里的位置
chr  (ascii表里的位置) = 字符

2.迭代中获取list/str下标

for i,ch in enumerate(str/list):
i 下标
ch 字符

3.获取字符串中某个字符的下标

在S字符串里面在[start,end)的区间里查找substr的下标

    S.index(substr,start ,end) -> idx(下标)

    S.rindex(substr,start ,end) ->idx(下标--右边开始的一个substr)
    # Like S.find() but raise ValueError when the substring is not found.
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章