0

Say if I want to do

num = int(input())
for i in range(num):
    print(num + 1)

for example, would it be possible to move input into the same line as the for statement and still refer to it within the for loop?

Andrej Kesely
  • 81,807
  • 10
  • 31
  • 56
Not Uplink
  • 15
  • 2

1 Answers1

0

You can use "walrus" assignment expression := if you're using Python 3.8+:

for i in range(num:=int(input())):
    print(num + 1)
Andrej Kesely
  • 81,807
  • 10
  • 31
  • 56