how to read the first line in a file python

f = open("test.txt", 'r')
variable = f.readline(1)

Here is what the above code is Doing:
1. It’s opening the file “test.txt” in read mode.
2. It’s reading the first line of the file and storing it in the variable “variable”.
3. It’s printing the contents of the variable “variable”.