Python 中的字串資料型別
用Python 表示字串的方式是在引號中標識出一組連續的字元。Python 允許使用單引號或雙引號。可以使用切片運算子 ([ ] 和 [:] ) 獲取子字串,其中索引從字串的開頭開始為 0,從結尾的 -1 計算。
示例
加號 (+) 是字串連線運算子,星號 (*) 是重複運算子。例如,
#!/usr/bin/python str = 'Hello World!' print str # Prints complete string print str[0] # Prints first character of the string print str[2:5] # Prints characters starting from 3rd to 5th print str[2:] # Prints string starting from 3rd character print str * 2 # Prints string two times print str + "TEST" # Prints concatenated string
輸出
將產生以下結果:
Hello World! H llo llo World! Hello World!Hello World! Hello World!TEST
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言
C++
C#
MongoDB
MySQL
Javascript
PHP