About 60,300 results
Open links in new tab
  1. python - How do I write a loop to repeat the code? - Stack Overflow

    Feb 5, 2021 · You can create a variable, and then say that as long as the variable is true to its value, to repeat the code in the for loop.

  2. 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.

  3. How to Repeat Code N Times in Python - Delft Stack

    Feb 14, 2021 · In this article, we’ve explored five methods to repeat a string of code N times in Python: using for loops, while loops, the itertools.repeat() function, list comprehension, and recursion. Each method has its use cases and advantages, so choose the one that best fits your requirements and coding style.

  4. How to Repeat N times in Python? (& how to Iterate?) - FavTutor

    Oct 25, 2022 · The repeat() function is the function that will actually let you repeat the code n number of times in python. 01) Using itertools.repeat() The itertools module provides a repeat() function in order to practice repeat in Python.

  5. How do I repeat the program in python - Stack Overflow

    Put the whole code in a while True loop and at the end ask the user if they want to repeat. If not, break the loop. Something like this: sentence=input("Please enter sentence(s)") words = sentence.split() number_of_words = len(words) counter=0. for x in sentence: if x in "!?.": counter=counter+1.

  6. 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 ...

  7. Easily Repeat Tasks Using Loops - OpenClassrooms

    Loops let you easily repeat tasks or execute code over every element in a list. A for loop enables you to repeat code a certain amount of time. A while loop lets you repeat code until a certain condition is met.

  8. How do i repeat the code multiple times? in python

    Oct 12, 2021 · For example if you want to run the code three times wrap it in a for loop: [here goes your code] or you could make a while loop and break: [here goes your code] if condition is met: break. you could use a for loop: #your code .

  9. Enki | Blog - How to Repeat Code in Python

    Repeating code in Python using for loops is both powerful and simple, making your code more readable and maintainable. You can iterate over various data structures such as lists, tuples, and dictionaries, or simply repeat an action using the range() function.

  10. Python Repeat: An In - Depth Exploration - CodeRivers

    Apr 5, 2025 · Understanding how to repeat operations effectively is crucial for writing efficient, clean, and scalable Python code. This blog post will delve into the various ways to achieve repetition in Python, from basic loops to more advanced techniques.

  11. Some results have been removed