zoukankan      html  css  js  c++  java
  • 02序列类型的各自方法


    ##序列类型 
    li=[1,2,3] #用dir查看函数类型 dir(li) 如果有__iter__ 就是可迭代类型

    li.append(4)#添加元素到末尾  返回 none
    解释 #append(...)
     #   L.append(object) -> None -- append object to end

    li.clear()#清除序列所有元素
    #clear(...) method of builtins.list instance
    #    L.clear() -> None -- remove all items from L

    li.copy() #复制出来的id不一样了 用id(object)查询
    #copy(...)
    #      L.copy() -> list -- a shallow copy of L

    li.count(1)#计算列表里面的元素出现的次数
    #count(...) method of builtins.list instance
    #   L.count(value) -> integer -- return number of occurrences of value

    help(help(li.extend) #可迭代的参数,依次添加到末尾
    #extend(...) method of builtins.list instance
    #   L.extend(iterable) -> None -- extend list by appending elements from the iterable

    li.index(3) #默认返回元素第一次出现的位子,可以添加一个查找范围
        #index(...) method of builtins.list instance
       #  L.index(value, [start, [stop]]) -> integer -- return first index of value.
        #  Raises ValueError if the value is not present.

     li.insert(3,'zhouxiaoyou')#指定索引插入元素
        
    # insert(...) method of builtins.list instance
    #    L.insert(index, object) -- insert object before index


    li.pop() #默认删除最后一个元素,也可以指定索引删除


    li.remove(2)#指定删除.

        
    li.reverse()#翻转


    li.sort()#默认以ascii码排序。
      #   sort(...) method of builtins.list instance
       # L.sort(key=None, reverse=False) -> None -- stable sort *IN PLACE*

    #sorted()
    #reversed

        

    ##元组打的方法
    tu=1,2
    tu.count(1)
    tu.index(1)   

    ##字符串的方法

    >>> s='565655656988781216'
        
    >>> s.count('5')
        
    5
    >>> s.count('0')
        
    0

    >>> s.endswith('6')#以什么结尾
        
    True
    >>> s.endswith('5')
        
    False


    >>> s.startswith('sd')#以什么开始
        
    False
    >>> s.startswith('sd\56')
        
    False
    >>> s.startswith('56')
        
    True


    s.find('5') #查找元素的索引位置
    >>> s.find('5')
        
    0
    >>> s.find('z')
        
    -1
    >>> s.find('5',3)
        
    4

                  
    s.index()


    s.isalpha()


    s.isdigit () :测试是否全是数字,都是数字则返回 True 否则返回 False.
                  
    s.islower () :测试是否全是小写
                  
    s.isupper () :测试是否全是大写
                  
    s.lower () :将字符串转为小写
                  
    s.upper () :将字符串转为大写
                  
    s.replace (x,y) :子串替换,在字符串s中出现字符串x的任意位置都用y进行替换
                  
    s.split():返回一系列用空格分割的字符串列表
                  
    s.split(a,b):a,b为可选参数,a是将要分割的字符串,b是说明最多要分割几个
                  
    s='c d df r af d gd d gdg '
    >>> s.split('d')
        
    ['c ', ' ', 'f r af ', ' g', ' ', ' g', 'g ']
    >>> s.split(' ')
        
    ['c', 'd', 'df', 'r', 'af', 'd', 'gd', 'd', 'gdg', '']
    >>> s.split('d',1)
        
    ['c ', ' df r af d gd d gdg ']
    >>> s.split('d',-1)
        
    ['c ', ' ', 'f r af ', ' g', ' ', ' g', 'g ']
    >>> s.split('d',-3)
        
    ['c ', ' ', 'f r af ', ' g', ' ', ' g', 'g ']


                  


        

  • 相关阅读:
    5 粘包现象与解决方案
    4 Socket代码实例
    协程与多路io复用epool关系
    基于selector的socket并发
    基于select类型多路IO复用,实现简单socket并发
    协程实现多并发socket,跟NGINX一样
    利用协程实现简单爬虫
    协程
    进程池pool
    进程锁 Lock
  • 原文地址:https://www.cnblogs.com/my123456/p/8437106.html
Copyright © 2011-2022 走看看