Python 字符串类型(day_008)

一、 定义

msg = 'hello world'
print(type(msg))  # <class 'str'>

二、 类型转换

str() 可以将任意类型转化为字符串类型。

res = str({'a': 1})
print(res, type(res))

三、 内置方法

3.1. 按索引取值(正向取+反向取) :只能取

# 正向取
print(msg[0])
print(msg[5])
print(msg[0:5])
# 反向取
print(msg[-1])
print(msg[-5])
print(msg[-5:-1])
发布了24 篇原创文章 · 获赞 2 · 访问量 407

猜你喜欢

转载自blog.csdn.net/weixin_46491071/article/details/104783261