For example, the contents of the txt file Assuming your name, weight, and height,
f =open("~.txt", "r")
print(f.realines())
f.close
I understand that if you write it like this, it's printed in a list format.
By the way,
f =open("~.txt", "r")
r = f.readlines()
for i in r :
print(i ,end="")
f.close
What's the reason why these cords are cut off and printed out?
Also, ir
< I've never seen this before. If it is not a repetitive sentence like ~in range
, what exactly does in r
mean?
The readlines()
function reads all sentences from a text file and returns them to the list. The list contains one line of text file contents.
For example, return a list stored as ['First Line Content', 'Second Line Content', 'Third Line Content',...]
The r
returned by r=f.readlines()
in the question is the list returned by storing the contents of the text file one line at a time.
If r
is a list in for r:
, the four-loop turns to take the elements of the list r
one by one and put them in i
.
If you look at the example below, r is the list, so the for loop turns and puts the elements of the list into i one by one. So if you look at the result, it's printed as print
one by one.
r=['1st line\n', '2nd line\n', '3rd line\n']
for i in r:
print(i)
563 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
586 GDB gets version error when attempting to debug with the Presense SDK (IDE)
571 PHP ssh2_scp_send fails to send files as intended
562 Who developed the "avformat-59.dll" that comes with FFmpeg?
849 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
© 2024 OneMinuteCode. All rights reserved.