• 各种对list,string操作函数的总结


    #encoding=utf-8
    #reverse,用来反转list
    a=['aa','bb','cc']
    a.reverse()
    print a#['cc', 'bb', 'aa']
    #不能直接print a.reverse(),报None
    #'tuple','dict','str' object has no attribute 'reverse',不能jiang字符串reverse

    #join以指定连接符连接tuple,list,strin,dict,输出为str类型
    seq1 = ['hello','good','boy','doiido']
    print ':'.join(seq1)#hello:good:boy:doiido
    seq2 = ('hello','good','boy','doiido')
    print ':'.join(seq2)
    seq3 = {'hello':1,'good':2,'boy':3,'doiido':4}
    print ':'.join(seq3)#boy:good:doiido:hello输出是乱的
    seq4 = 'hello good boy doiido'
    print ':'.join(seq4)#h:e:l:l:o: :g:o:o:d: :b:o:y: :d:o:i:i:d:o

    #split拆分字符串
    a='hello good boy doiido'
    print a.split()#['hello', 'good', 'boy', 'doiido']输出是list,括号内是根据什么字符来分割
    #'list','tuple','dict' object has no attribute 'split'

    #append,insert,remove,pop用法,只能操作list
    b=['hello','good','boy','doiido']
    b.append('hola')
    print b#['hello', 'good', 'boy', 'doiido', 'hola']
    b.insert(2,'luck')#['hello', 'good', 'luck', 'boy', 'doiido', 'hola']
    print b
    b.remove('hola')#['hello', 'good', 'luck', 'boy', 'doiido']
    print b
    print b.pop()#doiido,str类型
    print b#['hello', 'good', 'luck', 'boy']

  • 相关阅读:
    Product of Array Except Self
    Sliding Window Maximum
    First Bad Version
    Perfect Squares
    IPsec Note
    BGP实验第9-10选路原则
    BGP选路第3条原则
    BGP选路原则第1条至第8条
    BGP选路原则笔记 Cyrus
    Lab Block hole of BGP
  • 原文地址:https://www.cnblogs.com/garvicker/p/9523865.html
Copyright © 2020-2023  润新知