About 190,000 results
Open links in new tab
  1. How to repeat individual characters in strings in Python

    If you want to repeat individual letters you can just replace the letter with n letters e.g. An alternative itertools -problem-overcomplicating-style option with repeat(), izip() and chain(): Or, "I know regexes and I'll use it for everything"-style option: Of …

  2. python - Repeat string to certain length - Stack Overflow

    What is an efficient way to repeat a string to a certain length? Eg: repeat('abc', 7) -> 'abcabca' Here is my current code: def repeat(string, length): cur, old = 1, string while len(s...

  3. Repeat String in Python - W3Schools

    Sometimes we need to repeat the string in the program, and we can do this easily by using the repetition operator in Python. The repetition operator is denoted by a '*' symbol and is useful for repeating strings to a certain length.

  4. How to Repeat a String in Python? - GeeksforGeeks

    Dec 12, 2024 · Using Multiplication operator (*) is the simplest and most efficient way to repeat a string in Python. It directly repeats the string for a specified number of times. s = "Hello! " # Repeat the string 3 times r= s * 3 print(r) Hello! Let's take …

  5. python - Character repeating in a string - Stack Overflow

    May 8, 2014 · General variation, which returns string, repeating each character in the original string n times: def multichar(text, n): return ''.join([x * n for x in text]) Explanation: ''.join(...) - glues everything in (...) together into one piece without spaces, i.e. ''.join('a', 'b', 'c') will return 'abc'. ' '.join('a', 'b', 'c') will return 'a b c'.

  6. How to repeat a String N times in Python | bobbyhadz

    Apr 9, 2024 · To repeat each character in a string N times: Use a generator expression to iterate over the string. Use the multiplication operator to repeat each character N times.

  7. 5 Clever Techniques for Repeating Strings in Python

    We can use the multiplication operator to repeat a string a specific number of times, combine string repetition and slicing to repeat a string to a certain length, use the join () method to insert a separator between repetitions, and use a generator expression and the map () function to repeat each character in a string a specific number of times.

  8. Python – Custom Consecutive character repetition in String

    Feb 28, 2023 · Given a String, repeat characters consecutively by number mapped in dictionary. Input: test_str = ‘Geeks4Geeks’, test_dict = {“G” : 3, “e” : 1, “4” : 3, “k” : 5, “s” : 3} Output: GGGeekkkkksss444GGGeekkkkksss Explanation: Each letter repeated as per value in dictionary.

  9. Python Repeat String - Learn By Practical Examples - Oraask

    Feb 24, 2021 · To repeat a string in Python, We use the asterisk operator ” * ” The asterisk. is used to repeat a string n (number) of times. Which is given by the integer value ” n ” and creates a new string value.

  10. How to Repeat a String Multiple Times in Python? - Python Guides

    Jan 29, 2025 · Learn how to repeat a string multiple times in Python using the `*` operator, join(), and loops. Includes practical examples for efficient string manipulation! Skip to content

  11. Some results have been removed
Refresh