
How to Use the repeat() Function in Python? - Python Guides
Jan 4, 2025 · Learn how to use Python's `repeat()` function from the `itertools` module! This tutorial covers syntax, examples, and tips for repeating values in loops.
python - for or while loop to do something n times - Stack Overflow
Jul 15, 2013 · In Python you have two fine ways to repeat some action more than once. One of them is while loop and the other - for loop. So let's have a look on two simple pieces of code: for i in range(n):
python - How do I write a loop to repeat the code? - Stack Overflow
Feb 5, 2021 · Create a function repeat and add your code in it. Then use while True to call it infinitely or for i in range(6) to call it 6 times: import requests def repeat(): addr = input() vendor = requests.get('http://api.macvendors.com/' + addr).text print(addr, vendor) while True: repeat()
python - How to repeat a function n times - Stack Overflow
Sep 9, 2011 · I'm trying to write a function in python that is like: def repeated(f, n): ... where f is a function that takes one argument and n is a positive integer. For example if I defined square as: def square(x): return x * x and I called. repeated(square, 2)(3) this would square 3, 2 times.
How to repeat a function N times or indefinitely in Python
Feb 16, 2023 · There are two ways you can repeat a function in Python: Use the for loop to repeat a function N times; Use the while loop to repeat a function indefinitely; This tutorial will show you examples of how to repeat a function in Python. Repeat a function N times in Python. To repeat a function N times in Python, you need to use the for loop and ...
How to Repeat N times in Python? (& how to Iterate?) - FavTutor
Oct 25, 2022 · In this article, we've discussed how to repeat in Python and how it brought up the need for loops and functions. Further, we've learned about repeat() functions in python, offered by modules like itertools, pandas, and NumPy. Apart from them, we've also seen a trick to repeat strings n times in Python.
SOLVED: How to loop n times in Python [10 Easy Examples]
Jan 9, 2024 · First one is to iterate over the sequence like List, Tuple, Set and Dictionary. And the other one is to iterate over the range of numbers. This version of for loop will iterate over a sequence of numbers using the range () function.
Python For Loops - W3Schools
With the for loop we can execute a set of statements, once for each item in a list, tuple, set etc. Print each fruit in a fruit list: The for loop does not require an indexing variable to set beforehand. Even strings are iterable objects, they contain a sequence of characters: Loop through the letters in the word "banana":
How to Repeat Code N Times in Python - Delft Stack
Feb 14, 2021 · Understanding how to repeat a specific operation N times allows you to streamline workflows and enhance productivity. This guide explores various methods, from classic for loops with the range() function to dynamic while loops, list comprehensions, itertools functions, and recursive approaches.
How to call a Function N times in Python - bobbyhadz
Apr 10, 2024 · Alternatively, you can use the itertools.repeat() class. This is a three-step process: Use a for loop to iterate over the iterator. Call the function on each iteration. def print_message(message): print(message) . number = number * 2 . print_message('bobbyhadz.com') print(number) # 👉️ 32.
- Some results have been removed