About 19,000,000 results
Open links in new tab
  1. python - How do I limit the amount of letters in a string - Stack Overflow

    Feb 11, 2015 · Python's input function cannot do this directly; but you can truncate the returned string, or repeat until the result is short enough. # method 1 answer = input("What's up, doc? …

  2. Limiting Python input strings to certain characters and lengths

    I'd like to know how to constrain user input in a raw_input to certain characters and to a certain length. For example, I'd like to show an error message if the user inputs a string that contains …

  3. Python truncate a long string - Stack Overflow

    Nov 20, 2024 · If you are using Python 3.4+, you can use textwrap.shorten from the standard library: Collapse and truncate the given text to fit in the given width. First the whitespace in text …

  4. How to Truncate a String to a Specific Length in Python? - Python

    Jan 24, 2025 · Learn how to truncate a string to a specific length in Python using slicing, textwrap, and custom functions. Includes examples for efficient string manipulation

  5. The best – but not good – way to limit string length | adam-p

    Apr 28, 2025 · Python 3: len(str) 1: 1: 1: 7: 5: 9: Swift: String.count: 1: 1: 1: 1: 1: 1: Those four measurements of string length are exemplars of the approaches common to most …

  6. Python: Format a specified string limiting the length of a string

    6 days ago · String Formatter with Length Limit. Write a Python program to format a specified string and limit the length of a string. Sample Solution: Python Code: # Define a string …

  7. Python String Length - W3Schools

    To get the length of a string, use the len() function. The len() function returns the length of a string: a = "Hello, World!" Well organized and easy to understand Web building tutorials with lots of …

  8. How can I restrict the length of a string in Python while making …

    Nov 29, 2024 · By encoding the string to a specific format, you can safely truncate it to the maximum allowed byte length before decoding it back to a string. For example, you can …

  9. How can i limit length string? - Python Forum

    Feb 10, 2020 · So i need change the script for limit value queue ['name'] to 128 symbols. How can i change the script? Thank you. will give you a string variable variable which is queue['name'] …

  10. Limit user input to certain length : r/learnpython - Reddit

    Jul 28, 2023 · It is easy to check input length once the input is entered (if using input()), but not obvious how it can be done without a library if the checking is to be done while the user is …

  11. Some results have been removed
Refresh