0

I want to remove the first 3 numbers of any string that I put in the input.

response = input("Insert String: ")

If I were to put any string in the response it would print it with the first 3 characters removed.

Guy
  • 46,488
  • 10
  • 44
  • 88
Pigeon
  • 11
  • 1

2 Answers2

4

You can use string slicing.

response=input("Insert string:")[3:]

For more information on how slicing works, check out Understanding slicing on Stack. Happy coding!

iteratedwalls
  • 223
  • 1
  • 9
0

Try:

response = input("Insert String: ")
prefixStr = response[:2]
last_3_chars = response[-3:]
print(last_3_chars, prefixStr, sep='\t')

Maybe? I'm not sure exactly what you mean. Please clarify your request.

Anony Mous
  • 345
  • 3
  • 10
  • 3
    The request is pretty clear tbh. – matszwecja Jun 13 '22 at 11:15
  • Just a note, this contains a mistake - `first_3_chars` will actually only be the first two chars. – iteratedwalls Jun 13 '22 at 11:19
  • @iteratedwalls apologies, you are correct. I will replace with `prefixStr` – Anony Mous Jun 13 '22 at 11:20
  • Now `last_3_chars` is undefined, and it's still the first two characters. Also, why do you need the tab sep? Python will automatically separate arguments to `print` with spaces. – iteratedwalls Jun 13 '22 at 11:21
  • Firstly, do you mean `first_3_chars`? And secondly, I prefer `'\t'` especially in a debug environment. Just personal preference. But yes, I see what you mean. I just prefer it, it's generally just more comfortable and easier to see, especially with large projects. – Anony Mous Jun 13 '22 at 11:24