How does raw_input().strip().split() in Python work in this code?

How does raw_input().strip().split() in Python work in this code?

In python you use a split(delimiter) method onto a string in order to get a list based in the delimiter that you specified (by default is the space character) and the strip() method removes the white spaces at the end and beginning of a string

So step by step the operations are:

raw_input()          # insert 0 5     
raw_input().strip()  #insert 0 5
raw_input().strip().split()  #[insert, 0, 5]

you can use split(;) by example if you want to convert strings delimited by semicolons insert;0;5

Lets take an example, you take raw input

string= I am a coder 

While you take input in form of a string, at first, strip() consumes input i.e. string.strip() makes it

string=I am a coder 

since spaces at the front and end are removed.
Now, split() is used to split the stripped string into a list
i.e.

string=[I, am, a, coder] 

How does raw_input().strip().split() in Python work in this code?

Nope, that would be .remove( ), .strip() just gets rid of white space at the beginning and end of the string.

Leave a Reply

Your email address will not be published. Required fields are marked *