python中print函数的用法,python语言中print函数的有关知识

  python中print函数的用法,python语言中print函数的有关知识

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

  因为我敢接触Python,不保证以后还会有其他用法,所以后面会不断补充。

  1.除以某个字符,例如“.”

  ?1 3 4 str=( www . Google . com )printstr str _ split=str . split( . )printstr _ split的结果如下:

  2.除以某个字符,再除以n次。如果你按“.”分一次。

  ?1 3 4 str=( www . Google . com )printstr str _ split=str . split( . ,1)打印str_split结果如下:

  3.被某个字符串分割。例如:“”

  ?1 3 4 str=( win XP win 7 win 8 win 8.1 )printstr _ split=str . split( )printstr _ split结果如下:

  4.按照某个字符串划分,n次划分。比如按 分两次。

  ?1 3 4 str=( win XP win 7 win 8.1 )printstr _ split=str . split( ,2) printstr _ split结果如下:

  5.根据某个字符(或字符串)进行划分并进行n次划分,将划分后的完整字符串(或字符)赋给新的(n-1)个变量。(注意:见开头描述)比如用“.”分割字符,将它们拆分一次,并将拆分后的字符串赋给两个变量str1和str2。

  ?1 3 4 URL=(www.google.com) str1,str2=URL.split( . ,1)打印str1打印str2结果如下:

  如果是str.split( . )[3:]表示以点为分隔符分割字符串,后面的括号是范围,[3:]表示从第四个字符串开始分割;例如:

  SRT= www . Google . Sohu . Sina . 163 . com . 777 . 888 . 999 . 333 . 555 . 222 . 111 . 333 . 444 . 000

  s1=srt.split( . )[3:]

  打印s1

  [新浪, 163 , com , 777 , 888 , 999 , 333 , 555 , 222 , 111 , 333 ,

  444, 000]

  注意:在用。数组[www , Google ,搜狐,新浪, 163 , com , 777 , 888 , 999 , 333 , 555 , 222]就形成了。

郑重声明:本文由网友发布,不代表盛行IT的观点,版权归原作者所有,仅为传播更多信息之目的,如有侵权请联系,我们将第一时间修改或删除,多谢。

留言与评论(共有 条评论)
   
验证码: