python - Delete characters from the end of a string

3

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

I need the string "a" to be the same size as "b", is it possible?

I need them the same size to do a cryptographic process, one would be the key and the other plaintext

    
asked by anonymous 15.04.2017 / 15:39

2 answers

3

Do this:

 a_cortado = a[:len(b)]

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

    
15.04.2017 / 15:48
0

Another way would be to do a slicing, look like this:

a_fatiado = (a[0:8])

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

    
28.07.2017 / 05:21