从字符串获取字符

基本类型 / 字符类型

text = "ABC"
char_a = text[0]
# char_a is 'A'
char_b = text[1]
# char_b is 'B'
char_c = text[2]
# char_c is 'C'

# A negative index counts from the end
char_last = text[-1]
# char_last is 'C'

# A string is a sequence of chars
char_arr = list(text)
# char_arr is ['A', 'B', 'C']

print(f"{char_a = }")
print(f"{char_b = }")
print(f"{char_c = }")
print(f"{char_last = }")
print(f"{char_arr = }")