Skip to content
CodeBook
Main Navigation
ToolBox
GitHub
Appearance
GitHub
Menu
Return to top
On this page
Table of Contents for current page
String 字符串
#
可以通过下标索引获取字符串的某一位字符
Python
Copy code
a = "Hello" print(a[0])
a = "Hello" print(a[0])
分片操作
#
string[left:right:step]
step表示每次间隔多少个元素
Python
Copy code
a = "Hello" # a[left:right:step] print(a[0::2]) # 倒叙输出 print(a[::-1])
a = "Hello" # a[left:right:step] print(a[0::2]) # 倒叙输出 print(a[::-1])
字符串拼接
#
Python
Copy code
a = "hello" + " world" print(a) # 直接使用加号 a = "hello"
a = "hello" + " world" print(a) # 直接使用加号 a = "hello"