zoukankan      html  css  js  c++  java
  • 适用于可迭代对象的通用函数

    join

    s = 'mumu'
    s1 = '_'.join(s)  # m_u_m_u
    
    li = ['mumu', '怪蜀黍', '好看']
    s = '+++'.join(li)  # mumu+++怪蜀黍+++好看
    

    可以利用join去掉列表输出时的引号,方法如下:

    li = ['a', 'b', 'c']
    pirnt(li)  # ['a', 'b', 'c']
    
    s = ', '.join(li)  # a, b, c
    print('[' + s + ']')  # [a, b, c]
    

    split

    s = 'm+u+m+u'
    li = s.split('+')  # ['m', 'u', 'm', 'u']

    join: list ----> str

    split: str ----> list

  • 相关阅读:
    导论
    Array
    Singleton
    Bridge
    Mediator
    interpreter
    Visitor
    Flyweight
    Command
    Chain Of Responsibility
  • 原文地址:https://www.cnblogs.com/MuMuyom/p/10628467.html
Copyright © 2011-2022 走看看