Monday, February 13, 2017

Converting String into List-Python

     In this tutorial I will share you how to convert a input string into list containing each character.
In python 3 we have combined function that is input() for reading any type of input.Consider the following example
                       >>> invalue=input()
                       1234567789
                       >>> print(type(invalue))
                       <class 'str'>
                        >>> print(invalue)
                       1234567789
              Here we are using the input() function to read the string and store the value into the variable invalue. Now in order to convert this string into list we use the list() as given below

                        >>> inlist=list(invalue)
                        >>> print(type(inlist))

                        <class 'list'>
                        >>> print(inlist)
                       ['1', '2', '3', '4', '5', '6', '7', '7', '8', '9']
             From the above example we can see that the string can be converted into list using list().