zoukankan      html  css  js  c++  java
  • Ptyhon中join()函数用法

    转自http://www.jb51.net/article/63598.htm

     
    #对序列进行操作(分别使用' '与':'作为分隔符)
     
    >>> seq1 = ['hello','good','boy','doiido']
    >>> print ' '.join(seq1)
    hello good boy doiido
    >>> print ':'.join(seq1)
    hello:good:boy:doiido
     
     
    #对字符串进行操作
     
    >>> seq2 = "hello good boy doiido"
    >>> print ':'.join(seq2)
    h:e:l:l:o: :g:o:o:d: :b:o:y: :d:o:i:i:d:o
     
     
    #对元组进行操作
     
    >>> seq3 = ('hello','good','boy','doiido')
    >>> print ':'.join(seq3)
    hello:good:boy:doiido
     
     
    #对字典进行操作
     
    >>> seq4 = {'hello':1,'good':2,'boy':3,'doiido':4}
    >>> print ':'.join(seq4)
    boy:good:doiido:hello
     
     
    #合并目录
     
    >>> import os
    >>> os.path.join('/hello/','good/boy/','doiido')
    '/hello/good/boy/doiido'

    string.join(words[, sep])Concatenate a list or tuple of words with intervening occurrences of sep. The default value for sep is a single space character. It is always true that string.join(string.split(s, sep), sep) equals s.

    str.join(seq)Return a string which is the concatenation of the strings in the sequence seq. The separator between elements is the string providing this method.

  • 相关阅读:
    考研_数据结构
    快速排序模板
    nginx设置跳转https
    PHP 构造函数
    js scroll事件
    php获取url中的参数
    js 的cookie问题
    yii2关联表
    sql优化之concat/concat_ws/group_concat
    yii2.0 url美化-apache服务器
  • 原文地址:https://www.cnblogs.com/ylw666/p/5683722.html
Copyright © 2011-2022 走看看