Code Lab BetaBUILD. RUN. DISCOVER.
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
PYTHON FILES / CHAPTER 05 / Learn / LESSON 04
Line by line:
lines = [] with open("data.txt", encoding="utf-8") as f: for line in f: clean = line.strip() if clean: lines.append(clean)
count = len(lines)
joined = "|".join(lines)
print(count)
print(joined)strip() and skip blank lines. join() glues without a trailing separator.
--- data.txt ---
alpha
beta
gamma
Learn: for line in f loop.
BATCH IDLE
›