简体   繁体   English

如何从字符串中删除前 2 个字符 - python

[英]How can I strip the first 2 characters from a string - python

The problem问题

There are so many ways to strip characters from a string but I need an answer that equates for me not knowing the variable.有很多方法可以从字符串中删除字符,但我需要一个等于我不知道变量的答案。

for example lets say I want to strip the first two characters of a string:例如,假设我想去除字符串的前两个字符:

stringtostrip = "h mario"

How can I strip h and the我怎样才能剥离h space before mario without using h or mario 之前的空格,使用h in the answer?在答案中? What I mean by that is that this is just an example - In reality, the variable will be the user input and I don't know what the first two characters will be, I just need them stripped.我的意思是这只是一个例子——实际上,变量将是用户输入,我不知道前两个字符是什么,我只需要去掉它们。 (If that makes any sense) (如果那有意义的话)

Any ideas or suggestions would be appreciated.任何想法或建议将不胜感激。

Thanks!!谢谢!!

new_variable = stringtostrip[2:]

This will start from the character at index position 2 (ie without the first two characters) and doesn't need you to know what those first 2 characters are.这将从索引 position 2 处的字符开始(即没有前两个字符),并且不需要您知道前两个字符是什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM