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条)