对字符串的赋值的方法

对字符串的赋值的方法


2024年4月15日发(作者:)

对字符串的赋值的方法

1. 使用单引号或双引号直接赋值,如:

python

my_str = 'Hello World'

2. 使用三个单引号或双引号赋值多行字符串,如:

python

my_str = '''This is a

multi-line

string.'''

3. 使用str()函数将其他类型的数据转换为字符串后再赋值,如:

python

my_str = str(123)

4. 使用format()方法格式化字符串后赋值,如:

python

name = 'Alice'

age = 25

my_str = 'My name is {} and I am {} years old.'.format(name, age)


发布者:admin,转转请注明出处:http://www.yc00.com/news/1713183712a2199410.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信