Home > Blockchain >  index all values except the last two values
index all values except the last two values

Time:10-16

If I have an input, and I want everything that was inputted except for the las to values, how can I do that in python?

For example, if I have the string "800kg" is there a way to obtain everything except for the last two values, in this case I just want the "800" because I want to work with the number. I'm working with input and the input of the user could be of any size, I just want everything the user input except for the last two values.

Any information could help, thank you!!

CodePudding user response:

You can use string slicing to grab all characters in a string except for the last two:

inp_str = "800kg"
trunc_str = inp_str[:-2]
  • Related