zoukankan      html  css  js  c++  java
  • python的split用法

    Python中没有字符类型的说法,只有字符串,这里所说的字符就是只包含一个字符的字符串!!!
    这里这样写的原因只是为了方便理解,仅此而已。

    1. 按照某一个分隔符分割一个字符串:

    >>> str = "my name is liu de hua"
    >>> str
    'my name is liu de hua'
    >>> split_str = str.split(' ')
    >>> print split_str
    ['my', 'name', 'is', 'liu', 'de', 'hua']
    >>> 

    2. 按照某一个分隔符分割“多少次”:

    >>> str 
    'my name is liu de hua'
    >>> split_str2 = str.split(' ', 2)
    >>> split_str2
    ['my', 'name', 'is liu de hua']
    >>> 

    3. 按某一字符(或字符串)分割,且分割n次,并将分割的完成的字符串(或字符)赋给新的(n+1)个变量。如:按‘.’分割字符,且分割1次,并将分割后的字符串赋给2个变量str1,str2

    >>> url = "www.google.com"
    >>> str1, str2 = url.split('.',1)
    >>> str1
    'www'
    >>> str2
    'google.com'
    >>> 
  • 相关阅读:
    YL杯超级篮球赛 (Standard IO)
    Window (Standard IO)
    toj1026 Network 双连通分量
    poj3177 Redundant Paths 双连通分量
    poj1144 Network 双连通分量
    bzoj1269
    bzoj1800
    CF911D
    CF910C
    CF910B
  • 原文地址:https://www.cnblogs.com/blogofwyl/p/4658555.html
Copyright © 2011-2022 走看看