View the Most Wanted LQ Wiki articles.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 01-06-2007, 12:32 AM   #1
Registered: Feb 2002
Location: Massachusetts
Distribution: Debian (Lenny)
Posts: 286

Rep: Reputation: 30
Question 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.
Old 01-06-2007, 01:33 AM   #2
Senior Member
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 243Reputation: 243Reputation: 243
To process a string in Python, you use indexes


s = "astring"
print s[4:] #remove first 4 characters.
pls read the tutorial at
to get better understanding...
Old 01-06-2007, 01:37 AM   #3
Registered: Jun 2004
Location: Nova Scotia, Canada!
Distribution: Ubuntu
Posts: 170

Rep: Reputation: 30
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:


Old 01-16-2007, 10:52 AM   #4
Registered: Oct 2005
Posts: 31

Rep: Reputation: 15
>>> s = '0123456789'
>>> s[1:]
>>> s = s[1:]
>>> s


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to modify the names of files and replace characters with other characters or symb peter88 Linux - General 2 12-10-2006 04:05 AM
Removing a colon and all characters before it, in a python list tangle Programming 4 09-12-2006 10:48 PM
Removing Characters when outputting to a script thedarkdestroyer Linux - Newbie 3 03-21-2006 04:13 PM

All times are GMT -5. The time now is 11:57 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration