LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Python - Removing first x characters (https://www.linuxquestions.org/questions/programming-9/python-removing-first-x-characters-516802/)

Mithrilhall 01-05-2007 11:32 PM

Python - Removing first x characters
 
Is there any easy way to remove the first x characters of a string? I'm looking for the equivalent of substr if possible.

ghostdog74 01-06-2007 12:33 AM

To process a string in Python, you use indexes

eg

Code:

s = "astring"
print s[4:] #remove first 4 characters.

pls read the tutorial at http://docs.python.org/tut/
to get better understanding...

jonwatson 01-06-2007 12:37 AM

While I'm not sure exactly what you're doing, I feel compelled to mention awk. If you're parsing a text file then awk may well be more suitable. There's a TON of functionality in awk that isn't really documented all that well in the awk man page. A good primer is here:

http://sparky.rice.edu/~hartigan/awk.html

HTH

Jon

billiejoex 01-16-2007 09:52 AM

>>> s = '0123456789'
>>> s[1:]
'123456789'
>>> s = s[1:]
>>> s
'123456789'


All times are GMT -5. The time now is 04:51 PM.