A. python strip()是什麼意思具體看我例子

關鍵是理解」s and s.strip()「 這個表達式的值。Python語法是這么運行的:

如果s is None,那麼s會被判斷為回False。而False不管和什麼做答and,結果都是False,所以不需要看and後面的表達式,直接返回s(注意不是返回False)。
如果s is not None,那麼s會被判斷為True,而True不管和什麼and都返回後一項。於是就返回了s.strip()。

B. java什麼函數跟python里的strip作用一樣

我記得是去掉 文本中句子開頭與結尾的符號的。因為在文本中每行開頭都有個"/n",代表換行。(印象中是這樣的) 一般是 for line in file: line.strip().split() 這樣就把每行的每個字元一個個分開,變成一個list。 好久沒碰了,你可以試試

C. python中strip()作用是什麼

我記得是去掉 文本中句子開頭與結尾的符號的。因為在文本中每行開頭都有個"/n",代表換行。(印象中是這樣的)
一般是
for line in file:
line.strip().split()
這樣就把每行的每個字元一個個分開,變成一個list。
好久沒碰了,你可以試試

D. python 利用切片操作,實現一個trim()函數,去除字元串首尾的空格,注意不要調用str的strip()方法

defmyTrim(s):
whiles[:1]=='':
s=s[1:]
whiles[-1:]=='':
s=s[:-1]
returns
t='t測試內容sss'
print(myTrim(t))

E. Python strip函數不起作用,是版本問題嗎

Python 里字元串是不能被改變的,所以 str.strip() 只能返回新的字元串。
類似的 str.replace() 之類的也是這樣。

F. python3.3,這里的strip為什麼不能去掉+-/*這些符號呢

返回值才是被移除掉指定字元的字元串。原來的字元串沒有改變。這個函數不是原地修改。

strip(s, chars=None)
strip(s [,chars]) -> string

Return a of the string s with leading and trailing
whitespace removed.
If chars is given and not None, remove characters in chars instead.
If chars is unicode, S will be converted to unicode before stripping.

G. python高手看過來,關於strip()函數會去掉首尾的指定字元,但是指定字元匹配到多次時怎麼只去掉一次呢

這個函數不是干你要求的工作的函數。它主要是用於快速去掉字元首尾的空格或回車。
做你的要求可以如下:
a='abcdeee'
if a.rfind('e',len(a)-1)>0:a=a[0:len(a)-1]
print(a)

H. python中的strip和split結合起來怎麼用

python strip() 函數和 split() 函數的詳解及實例
一直以來都分不清楚strip和split的功能,實際上strip是刪除的意思;而split則是分割的意思。因此也表示了這兩個功能是完全不一樣的,strip可以刪除字元串的某些字元,而split則是根據規定的字元將字元串進行分割。下面就詳細說一下這兩個功能,
1 Python strip()函數 介紹
函數原型
聲明:s為字元串,rm為要刪除的字元序列
s.strip(rm) 刪除s字元串中開頭、結尾處,位於 rm刪除序列的字元
s.lstrip(rm) 刪除s字元串中開頭處,位於 rm刪除序列的字元
s.rstrip(rm) 刪除s字元串中結尾處,位於 rm刪除序列的字元
注意:
(1)當rm為空時,默認刪除空白符(包括'\n', '\r', '\t', ' ')
(2)這里的rm刪除序列是只要邊(開頭或結尾)上的字元在刪除序列內,就刪除掉。
例如,

>>> a = ' 123'
>>> a
' 123'
>>> a.strip()
'123'

(2)這里的rm刪除序列是只要邊(開頭或結尾)上的字元在刪除序列內,就刪除掉。

例如,

>>> a = '123abc'
>>> a.strip('21')
'3abc'
>>> a.strip('12')
'3abc'

結果是一樣的。

2 python split()函數 介紹

說明:

Python中沒有字元類型的說法,只有字元串,這里所說的字元就是只包含一個字元的字元串!!!

這里這樣寫的原因只是為了方便理解,僅此而已。
(1)按某一個字元分割,如『.'
>>> str = ('www.google.com')
>>> print str
www.google.com
>>> str_split = str.split('.')
>>> print str_split
['www', 'google', 'com']

(2)按某一個字元分割,且分割n次。如按『.'分割1次
>>> str_split = str.split('.',1)
>>> print str_split
['www', 'google.com']

(3)split()函數後面還可以加正則表達式,例如:
>>> str_split = str.split('.')[0]
>>> print str_split
www

split分隔後是一個列表,[0]表示取其第一個元素;

>>> str_split = str.split('.')[::-1]
>>> print str_split
['com', 'google', 'www']
>>> str_split = str.split('.')[::]
>>> print str_split
['www', 'google', 'com']

按反序列排列,[::]安正序排列
>>> str = str + '.com.cn'
>>> str
'www.google.com.com.cn'
>>> str_split = str.split('.')[::-1]
>>> print str_split
['cn', 'com', 'com', 'google', 'www']
>>> str_split = str.split('.')[:-1]
>>> print str_split
['www', 'google', 'com', 'com']

從首個元素開始到次末尾,最後一個元素刪除掉。
split()函數典型應用之一,ip數字互換:
# ip ==> 數字
>>> ip2num = lambda x:sum([256**j*int(i) for j,i in enumerate(x.split('.')[::-1])])
>>> ip2num('192.168.0.1')
3232235521

# 數字 ==> ip # 數字范圍[0, 255^4]
>>> num2ip = lambda x: '.'.join([str(x/(256**i)%256) for i in range(3,-1,-1)])
>>> num2ip(3232235521)
'192.168.0.1'

最後,python怎樣將一個整數與IP地址相互轉換?
>>> import socket
>>> import struct
>>> int_ip = 123456789
>>> socket.inet_ntoa(struct.pack(『I',socket.htonl(int_ip)))#整數轉換為ip地址
『7.91.205.21'
>>> str(socket.ntohl(struct.unpack(「I」,socket.inet_aton(「255.255.255.255″))[0]))#ip地址轉換為整數
『4294967295'

I. python當中strip()是起什麼作用的舉例說明一下,謝謝

告知你一個捕魚的方法:
>>> import string
>>> help(string.strip)
Help on function strip in mole string:
strip(s, chars=None)
strip(s [,chars]) -> string

Return a of the string s with leading and trailing
whitespace removed.
If chars is given and not None, remove characters in chars instead.
If chars is unicode, S will be converted to unicode before stripping.
用help()查詢 模塊,方法等的用途。

J. python 中strip().split()這樣寫是否合法

這樣是合法的,但是不是你說的一個是一個內部的函數,而是前者返回值可以繼續下一個操作。也就是strip返回的是str類型,當然也可以split操作。