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?
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?
You can use "walrus" assignment expression :=
if you're using Python 3.8+:
for i in range(num:=int(input())):
print(num + 1)