Possible Duplicate:
Is there a way to substring a string in Python?
I have a string in the form ‘AAAH8192375948’. How do I keep the first 5 characters of this string, and strip all the rest? Is it in the form l.strip with a negative integer? Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A string in Python is a sequence type, like a list or a tuple. Simply grab the first 5 characters:
The slice notation is
[start:end:increment]— numbers are optional if you want to use the defaults (start defaults to 0, end to len(my_sequence) and increment to 1). So:stripremoves a character or set of characters from the beginning and end of the string – entering a negative number simply means that you are attempting to remove the string representation of that negative number from the string.