多行字串

Python

來源:Python Software Foundation

變數想要儲存多行字串可以用「“”“」來包住多行字串:

print("""\
Usage: thingy [OPTIONS]
 -h Display this usage message
 -H hostname Hostname to connect to
""")

字串切片

Python

來源:Python Software Foundation

無敵記憶法,第一列表示「前兩個字」;第三列表示「除前兩個字外的其它全部」:

>>> word[:2] # The first two characters
’He

>>> word[2:] # Everything except the first two characters
’lpA

參考資料