Skip to content

Instantly share code, notes, and snippets.

@pointofpresence
Last active March 31, 2024 12:15
Show Gist options
  • Save pointofpresence/48c0411dd798623b4272a6805205f83c to your computer and use it in GitHub Desktop.
Save pointofpresence/48c0411dd798623b4272a6805205f83c to your computer and use it in GitHub Desktop.
Внутри цикла while используется оператор присваивания :=, который появился в Python 3.8. Он читает очередную строку из файла с помощью метода readline() и присваивает ее переменной line.
with open(filename) as file:
while line := file.readline():
print(line.rstrip())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment