python打印输出代码
时间: 2024-03-12 15:42:28 浏览: 85
当你在Python中编写代码时,可以使用print()函数来进行打印输出。print()函数用于将指定的内容输出到控制台或者文件中。
以下是一些常见的Python打印输出代码示例:
1. 打印字符串:
```python
print("Hello, World!")
```
2. 打印变量的值:
```python
name = "Alice"
age = 25
print("My name is", name, "and I am", age, "years old.")
```
3. 格式化输出:
```python
name = "Bob"
age = 30
print("My name is {} and I am {} years old.".format(name, age))
```
或者使用f-string:
```python
name = "Bob"
age = 30
print(f"My name is {name} and I am {age} years old.")
```
4. 打印多行文本:
```python
text = """
This is a multi-line
text example.
"""
print(text)
```
5. 打印列表或元组:
```python
fruits = ["apple", "banana", "orange"]
print(fruits)
numbers = (1, 2, 3, 4, 5)
print(numbers)
```
6. 打印字典:
```python
person = {"name": "Alice", "age": 25}
print(person)
```
以上是一些常见的Python打印输出代码示例,你可以根据具体的需求进行调整和扩展。
阅读全文