**如下:
#encoding=utf-8
print '中國'
#字串對齊
print '|','abc中國'.ljust(20),'|','abc中國'.rjust(20),'|','abc中國'.center(20),'|'
print u'|',u'abc中國'.ljust(20),u'|',u'abc中國'.rjust(20),u'|',u'abc中國'.center(20),u'|'
print u'|',u'abc中國'.ljust(20,'-'),u'|',u'abc中國'.rjust(20,'-'),u'|',u'abc中國'.center(20,'-'),u'|'
列印結果如下:
中國| abc中國 | abc中國 | abc中國 |
| abc中國 | abc中國 | abc中國 |
| abc中國--------------- | ---------------abc中國 | -------abc中國-------- |
python字串 Python 字串
建立字串很簡單,只要為變數分配乙個值即可。例如 var1 hello world var2 python runoob python訪問字串中的值python不支援單字元型別,單字元在 python 中也是作為乙個字串使用。python訪問子字串,可以使用方括號來擷取字串,如下例項 例項 pytho...
python字串 python字串
單引號示例常用的轉義字元 轉義字元案例1format 格式化練習1 help sisdigit,isnumeric,isdecimal 三個判斷數字的函式 isalnum 檢查字串是否由字母加數字組成 s test1split 字串拆分 splitlines 已換行符拆分 join 合成字串 upp...
python字串用法 python字串使用總結
python 字串使用總結 字串是程式中最常見的資料型別。在 python 中,可以使用三種方式定義字串。單 引號 雙引號和三引號。例如 string string string 或者是 string 在使用上,單引號和雙引號沒有什麼區別。三引號的主要功能是在字串中可以 包含換行 也就是說,在三引號...