• 各种对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']

  • 相关阅读:
    POJ3613 k边最短路
    洛谷4014最大/小费用最大流
    POJ1734无向图求最小环
    洛谷4013数字梯形
    洛谷4147玉蟾宫
    洛谷4145上帝造题的七分钟2
    洛谷4092 树
    Nginx动静分离-tomcat
    nginx之Geoip读取地域信息模块
    Nginx与Lua开发
  • 原文地址:https://www.cnblogs.com/garvicker/p/9523865.html
Copyright © 2020-2023  润新知