How to repeat N times in Python

3 Answers

0 votes
N = 5
 
for i in range(N):
    print("python", i)
 
 
 
'''
run:
 
python 0
python 1
python 2
python 3
python 4
 
'''

 



answered Apr 24, 2021 by avibootz
0 votes
N = 7

for _ in range(N):
    print("python")



'''
run:

python
python
python
python
python
python
python

'''

 



answered Apr 24, 2021 by avibootz
0 votes
import itertools

N = 5
 
for _ in itertools.repeat(None, N):
    print("python")
    
 
 
 
'''
run:
 
python
python
python
python
python
 
'''

 



answered Apr 24, 2021 by avibootz

Related questions

1 answer 157 views
2 answers 244 views
1 answer 81 views
1 answer 103 views
1 answer 89 views
89 views asked Dec 23, 2024 by avibootz
1 answer 109 views
109 views asked Dec 23, 2024 by avibootz
...