python一行输出多个变量值
时间: 2023-07-01 15:10:26 浏览: 129
python实现同时给多个变量赋值的方法
你可以使用字符串格式化方法来输出多个变量值,例如:
```python
name = "Alice"
age = 25
city = "New York"
print("My name is {}, I'm {} years old and I live in {}.".format(name, age, city))
```
这将输出:`My name is Alice, I'm 25 years old and I live in New York.`
你也可以使用 f-strings (格式化字符串字面值) 来简化代码:
```python
name = "Alice"
age = 25
city = "New York"
print(f"My name is {name}, I'm {age} years old and I live in {city}.")
```
这将输出相同的结果:`My name is Alice, I'm 25 years old and I live in New York.`
阅读全文