Python 3.1 快速導覽 - 字串型態的 splitlines()

字串 (string) 型態 (type) 的 splitlines() 方法 (method) ,將 str 以新行符號分割成子字串,回傳儲存子字串的串列

方法描述
str.splitlines([keepends])將 str 以新行符號分割成子字串,回傳儲存子字串的串列


舉例示範如下
a = "Free\n your\n mind."
b = "Welcome to the desert... \nof the real."
c = "What is real?\n How do you define real?"
d = "There is no spoon."

print(a)
print(a.splitlines())
print()

print(b)
print(b.splitlines())
print()

print(c)
print(c.splitlines())
print()

print(d)
print(d.splitlines())
print()

# 《程式語言教學誌》的範例程式
# http://pydoing.blogspot.com/
# 檔名:splitlines.py
# 功能:示範 Python 程式 
# 作者:張凱慶
# 時間:西元 2010 年 12 月


執行結果如下



中英文術語對照
字串string
型態type
方法method


內建型態




沒有留言: