python read
时间: 2023-09-10 12:06:21 浏览: 64
pythonreader
5星 · 资源好评率100%
In Python, the "read" function is used to read data from a file. This function is used in conjunction with the "open" function, which is used to open a file. Here is an example code snippet showing how to use the "read" function:
```
# Open the file
file = open("example.txt", "r")
# Read the contents of the file
data = file.read()
# Close the file
file.close()
# Print the data
print(data)
```
In this example, the "open" function is used to open the file named "example.txt" in read mode ("r"). The "read" function is then used to read the contents of the file into the variable named "data". Finally, the "close" function is used to close the file, and the contents of the file are printed to the console using the "print" function.
阅读全文