strip()和split()常常結(jié)合使用,特別是在處理包含多余空白或特殊字符的字符串時(shí)。 1)移除空格后再分割 1 2 3 4 text=" apple, banana, orange " cleaned_text=text.strip() fruits=cleaned_text.split(', ') print(fruits)# 輸出: ['apple', 'banana', 'orange'] 在這個(gè)例子中,先用strip()刪除字符串...
www.dbjr.com.cn/python/3370462...htm 2025-6-5