Linked Questions
73 questions linked to/from How do I get a substring of a string in Python?
Score of 4708
38 answers
3271048 views
How slicing in Python works
How does Python's slice notation work? That is: when I write code like a[x:y:z], a[:], a[::2] etc., how can I understand which elements end up in the slice?
See Why are slice and range upper-bound ...
Score of 544
2 answers
925374 views
Get the last 4 characters of a string [duplicate]
I have the following string: "aaaabbbb"
How can I get the last four characters and store them in a string using Python?
Score of 36
8 answers
155399 views
How can I remove the last character of a string in python? [duplicate]
I have a file path as a string and trying to remove the last '/' from the end.
my_file_path = '/home/ro/A_Python_Scripts/flask-auto/myDirectory/scarlett Johanson/1448543562.17.jpg/'
I've been trying ...
Score of 28
3 answers
96724 views
Strip all but first 5 characters - Python [duplicate]
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 ...
Score of 10
1 answer
86689 views
How to return the last character of a string in Python? [duplicate]
How can I get the last character of this string?
seed_name = "Cocoa"
Score of -1
2 answers
76477 views
Printing specific parts of a string in python [duplicate]
def PrintThree(s):
x = len(s)
return s[0:3] + x[3:]
I am pretty stuck right now on how to print only certain parts of a string. I am trying to make a code where python will print 3 ...
Score of 4
1 answer
5254 views
Python strip a string from index [duplicate]
I have a list of strings in the format: 'foo7bar'. How is it possible in Python to remove the 7 along with any characters that follow?
This is similar to this question, but I need the answer for ...
Score of 1
5 answers
4147 views
How do I split a list of numbers into a phone number in python? [duplicate]
I am trying to answer a question for a homework assignment. I have to split an input of numbers into a phone number. The input is 8005551212 and the output needs to look like 800-555-1212.
My question ...
Score of 2
2 answers
1400 views
python string manipulation, finding a substring within a string [duplicate]
I am trying to find a substring within a larger string in python. I am trying to find the text present after the string "Requests per second:" is found. It seems my knowledge of python strings and ...
Score of 1
1 answer
2829 views
How to display all letters in a string except the first [duplicate]
I want to display an input() string and want to display it so it prints all the letters of the string except the first letter.
string1 = input("enter first string")
string2 = input("enter second ...
Score of -6
1 answer
1529 views
Remove "x" number of characters from a string? [duplicate]
In Python: How do I write a function that would remove "x" number of characters from the beginning of a string?
For instance if my string was "gorilla" and I want to be able remove two letters it ...
Score of -2
1 answer
1314 views
How to extract the last 2 characters of a variable with substring [duplicate]
I need to extract the last two characters of a phrase, but I don't know how as there isn't a minus 0.
Score of 1
2 answers
882 views
This function creates and returns a list of all countries whose nth letter matches the letter in the parameter in Python [duplicate]
get_list_of_countries_whose_nth_letter_is(3, “m”) would return a list of every country whose THIRD letter (i.e. index 2) is the letter m:
['Armenia', 'Cambodia', 'Cameroon', 'Comoros', 'Dominica', '...
Score of -2
3 answers
1265 views
Finding all possible 5-letters combinations in a word using Regex (Python) [duplicate]
I'm new to Python and to Regex. Here is my current problem, for which I have not managed to find any straight answer online.
I have a string of 5 or more characters, for which I need to search for all ...
Score of -2
1 answer
161 views
How to move the beginning of an input to the and? [duplicate]
Let's say I have an input:
SA3213023215
I want to move the SA to the very end of the input.
How can I do this?