How to split user input in python? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 13

How to split user input in python?

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

5th Jan 2018, 10:01 AM
Manish Mehta
Manish Mehta - avatar
26 Answers
+ 72
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']
5th Jan 2018, 10:20 AM
Nikhil
Nikhil - avatar
+ 18
@Ace :- split() doesn't work here For example :- a = "Nikhil" b = a.split() print(b) would just print ['Nikhil'] It doesn't split.
5th Jan 2018, 10:54 AM
Nikhil
Nikhil - avatar
+ 9
Nikhil split() function splits a string by spaces into words, am I right?
4th Jul 2021, 12:40 PM
Xemonix
Xemonix - avatar
+ 4
St=[] St=input ("enter a string") For x in st: Print (st[0::])
14th Apr 2021, 2:39 PM
Mayank Hemnani
Mayank Hemnani - avatar
+ 3
U could try the .extend() method For example a= "Nikhil" b= a.extend()
7th Jul 2021, 10:22 AM
Abraham Onuh
Abraham Onuh - avatar
+ 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)
4th Oct 2021, 8:11 PM
fajnah6
+ 2
If you mean a string you can split strings in python they are a form of list
11th Oct 2021, 4:42 PM
Adesewa Adesida
Adesewa Adesida - avatar
+ 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 👌🏻
9th Feb 2022, 12:10 AM
Osei Michael
Osei Michael - avatar
+ 2
love=input("insert your verb") splitted=list(love) print(splitted) My Input = i love universe ["I","l","o","v","e", im lazy etc.....]
18th Mar 2022, 4:09 PM
Abülfazl Molavi
Abülfazl Molavi - avatar
+ 2
#include <iostream> using namespace std; int main() { int count = 300; int time; cin >> time; count *= time; cout << count << endl; return 0; }
24th Oct 2022, 12:11 PM
Anush Grigoryan
Anush Grigoryan - avatar
+ 1
inp = input("Your input here") splitted = list(inp) Here I'm using, Ritviz:- splitted = ['R','i','t','v','i','z']
1st Sep 2021, 10:09 AM
reallyraushan
reallyraushan - avatar
+ 1
text = input() stext= [x for x in text] print(stext)
27th Oct 2021, 11:47 PM
Bavikatti Shwetha
+ 1
Input=(‘x’) Splitted=li’(x)
7th Mar 2022, 9:27 AM
Honeycrown
+ 1
Vshsn
23rd Mar 2022, 12:45 PM
Grey Рылов
Grey Рылов - avatar
+ 1
name= input (what's yourname)
26th Apr 2022, 8:25 AM
kirolos shady wessa
kirolos shady wessa - avatar
+ 1
Use list function
26th May 2022, 1:28 PM
Amir Almasy
Amir Almasy - avatar
0
Put \n Before them
19th Jun 2021, 6:20 AM
Mr.Max
Mr.Max - avatar
0
Just use .. splitted = ['S','o','l','o','l','e','a','r','n']
1st Sep 2021, 8:50 AM
YashVibes
YashVibes - avatar
0
Use split() function
29th Sep 2021, 12:48 PM
Rishav Kumar
Rishav Kumar - avatar
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)
11th Nov 2021, 3:41 AM
Gowtham AG
Gowtham AG - avatar