zoukankan      html  css  js  c++  java
  • 序列类型方法

    ##序列类型的方法
    
    #列表的方法
    
    li.append() #将这个元素添加末尾
    li.clear()  #清空列表
    li.copy() #复制列表
    
    li.count(2) #统计这个元素的个数
    li.extend([4,5,6]) #将可迭代对象分开依次添加到末尾
    li.index('c') #默认返回这个元素最先出现的索引位置
    
    
    li.insert(1,'lucky')# 将‘lucky’插入到索引为1的位置
    li.pop() #默认删除最后一个,可以根据索引位置删除
    li.remove('c') #指定移除
    
    
    li.reverse() # 反转列表
    li.sort()  #排序
    
    
    ##元组的方法
    tu.count(1)
    tu.index(2)
    
    
    ##字符串的方法
    s.count('3')
    s.endswith('a') #判断以‘a’结尾
    s.startswith('a') #判断以a 开始    返回值都是bool
    
    s.find('b')  #返回索引位置  找不到就返回-1
    s.index('b') #默认返回最先出现的索引位置 同样可以填范围
    
    s.isalpha() #测试全是字母,返回bool
    s.isdigit() #测试全是正整数
    s.isupper()
    s.islower()
    
    s.replace('a','b',1) #将存在的元素替换成新的元素,可以选择换几次
    s.split()  #默认以空格分割

    #1.用3种方法,往列表里面插值

    a=[1,2,3,4]

    a.append(7)

    a.insert(1,6)

    a.extend([5]) 

    #2.给定列表 li =['a','b','c','d'],要求用2种方法, 将列表'c'元素,替换成'lucky'
    # li=['a','b','lucky','d']

    1. li[2]='lucky'

    2. li.pop(2)   li.insert(2,'lucky')

    #3.te = 'string test' 如何把te 中的'test' 替换成'OK'

    te=te.replace('test','OK')

    #4.将字符串 s ='hello python !',转换成列表 li=['hello','python','!']

    li=s.split()

  • 相关阅读:
    tf.py_func函数总结
    CS231N 常用激活函数
    CS231N 数据预处理(data proprecessing)
    RNN
    plt.subplot与subplot的区别
    Faster-rcnn代码中bbox_inside_weights的作用是什么
    Python基础之python数据结构
    asp.net分割字符串的几种方法
    .net后台获取HTML中select元素选中的值
    JQuery+Ajax制作省市联动
  • 原文地址:https://www.cnblogs.com/taoge188/p/8303019.html
Copyright © 2011-2022 走看看