0

I actually want to know how i can actually only show the first characters of a string and show after the first characters a "...".

I already searched a bit and found:

I want to show only the first 10 characters:

character_name = "им ٠ frag /watch?v=Q-2tZ8ttE"
name = character_name[10:]

Edit: I forgot to mention that it could be also the case, that the name is less than 10 characters and there shouldnt be a "..." afterwards. Only for names which contain more than 10 Characters. But how i can add afterwards a "..." after the 10 characters?

Fragkiller
  • 589
  • 2
  • 8
  • 21

1 Answers1

1

I think you want something like this,

>>> def remove(s):
        if len(s) > 9:
            return character_name[:10] + '...'


>>> print remove('им ٠ frag /watch?v=Q-2tZ8ttE')
им ٠ fr...
>>> print remove('им ٠ fr')
им ٠ fr...
>>> print remove('им ٠ f')
None
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274