How to split user input in python? | Sololearn: Learn to code for FREE!

+11

How to split user input in python?

For example : i want to split golden to 'g','o','l','d','e','n'.... THANK YOU!

1/5/2018 10:01:57 AM

Manish Mehta

20 Answers

New Answer

+58

inp = input("Your input here") splitted = list(inp) Now splitted is a list with values like this :- Suppose I gave input as Sololearn :- splitted = ['S','o','l','o','l','e','a','r','n']

+16

@Ace :- split() doesn't work here For example :- a = "Nikhil" b = a.split() print(b) would just print ['Nikhil'] It doesn't split.

+7

St=[] St=input ("enter a string") For x in st: Print (st[0::])

+5

Nikhil split() function splits a string by spaces into words, am I right?

+3

If you want it in one line use: var1 = input() var2 = list(var1) print(var2) Or if you want it in separate lines: var1 = input() for var2 in var1: print(var2)

+2

Why dont you use for loop in compination with list For example: Word = input() Split_word = [] For i in word: Split_word.append(i) This works better and simple 👌🏻

+2

love=input("insert your verb") splitted=list(love) print(splitted) My Input = i love universe ["I","l","o","v","e", im lazy etc.....]

+1

U could try the .extend() method For example a= "Nikhil" b= a.extend()

+1

inp = input("Your input here") splitted = list(inp) Here I'm using, Ritviz:- splitted = ['R','i','t','v','i','z']

+1

If you mean a string you can split strings in python they are a form of list

+1

text = input() stext= [x for x in text] print(stext)

+1

Input=(‘x’) Splitted=li’(x)

+1

+1

name= input (what's yourname)

+1

Use list function

0

Put \n Before them

0

Just use .. splitted = ['S','o','l','o','l','e','a','r','n']

0

Use split() function

0

You can use `list()` function, user_inp = input("enter input: ") splitted_string = list(user_inp) Now print the splitted_string variable to the desired output print (splitted_string)

0

No need to split or anything you can simply acees it with array index for ex Name = input ("enter your name") Print(name[0]) //Suppose name is nikhil then it will print n which is the first character present at index 0.