python limit number of characters in string
Python[Edit]
+
0
-
0
python limit number of characters in string
1 2 3 4 5 6 7 8 9 10 11 12 13 14def limitString(string, limit): if len(string) > limit: return string[0:limit] else: return string # Usage example: text = 'ABCDE' print(limitString(text, 1)) # 'A' print(limitString(text, 2)) # 'AB' print(limitString(text, 3)) # 'ABC'
[Edit]
+
0
-
0
python limit number of characters in string
1 2 3 4 5 6 7 8 9 10# 1 5 # | | text = 'Example text...' limit = 5 if len(text) > limit: text = text[0:limit] print(text) # 'Examp'