python print输出字符串
时间: 2023-09-08 09:13:51 浏览: 122
在Python中,要输出字符串,你可以直接将字符串作为`print()`函数的参数传递。以下是一个示例:
```python
string = "Hello, world!"
print(string) # 输出字符串
```
这将输出字符串`Hello, world!`。你也可以在`print()`函数中同时输出多个字符串,只需用逗号分隔它们:
```python
string1 = "Hello"
string2 = "world!"
print(string1, string2) # 输出多个字符串
```
这将输出字符串`Hello`和字符串`world!`。此外,你还可以使用字符串格式化来输出带有变量的字符串,例如:
```python
name = "Alice"
age = 25
print("My name is %s and I am %d years old." % (name, age)) # 带有变量的字符串格式化输出
```
这将输出类似于`My name is Alice and I am 25 years old.`的字符串。希望这对你有所帮助!
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)