python常用代码段
时间: 2024-01-16 10:18:48 浏览: 86
以下是两个常用的Python代码段:
1. 读取文件内容并打印:
```python
with open('filename.txt', 'r') as file:
content = file.read()
print(content)
```
2. 格式化字符串输出:
```python
name = 'Alice'
age = 25
print('My name is {} and I am {} years old.'.format(name, age))
```
阅读全文