python - Delete string end characters

Asked

Viewed 798 times

3

Is there any way to delete characters at the end of a string in python? For example: a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" B = "ABCDEFGH"

I need string "a" to be the same size as "b," so that’s possible?

I need them of the same size to make an encryption process, one would be the key and the other the plaintext

2 answers

3


Do so:

 a_cortado = a[:len(b)]

By doing so, you will be cutting the string of a exactly the same size as b.

  • It worked perfect! Thank you very much!!!

  • That’s good, man. If this solved the problem, consider marking the question as you accept or vote positively :p

0

Another way would be to slice it up, get like this:

a_fatiado = (a[0:8])

similar way the first solution presented but without using the 'Len' function'.

  • But this is exactly the same solution presented in the other answer. What would be this other way that commented?

  • That the parentheses change ?

  • A similar way to the first solution presented but without using the 'Len' function'.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.