zoukankan      html  css  js  c++  java
  • 各种对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']

  • 相关阅读:
    四、运算符
    三、Golang 变量
    二、Golang的概述
    一、Golang开山篇
    部分技术使用
    Teleport_实战
    zabbix_浅谈
    渗透测试工具集合(漏洞练习平台)
    常见开源监控软件的介绍
    Ansible-大保健
  • 原文地址:https://www.cnblogs.com/garvicker/p/9523865.html
Copyright © 2011-2022 走看看