python print带参数
时间: 2023-09-25 11:16:06 浏览: 86
如何运行带参数的python脚本
在Python中,`print()`函数是用于输出文本或对象的标准输出函数。该函数可以接受多个参数,并将它们打印在屏幕上。以下是一些常见的用法:
1. 打印一个字符串
```python
print("Hello World!")
```
2. 打印多个字符串
```python
print("Hello", "World!")
```
3. 打印一个变量
```python
name = "Alice"
print(name)
```
4. 打印多个变量
```python
name = "Alice"
age = 25
print(name, age)
```
5. 打印一个字符串和一个变量
```python
name = "Alice"
print("My name is", name)
```
6. 打印一个字符串和一个变量,使用字符串格式化
```python
name = "Alice"
print("My name is %s" % name)
```
7. 打印多个变量,使用字符串格式化
```python
name = "Alice"
age = 25
print("My name is %s and I am %d years old" % (name, age))
```
8. 打印一个变量,使用f-string
```python
name = "Alice"
print(f"My name is {name}")
```
9. 打印多个变量,使用f-string
```python
name = "Alice"
age = 25
print(f"My name is {name} and I am {age} years old")
```
阅读全文