Learn Python – Free Interactive Python Tutorial

Welcome

free interactive Python tutorial for people who want to learn Python, fast.

Welcome to the thesoft interactive Python tutorial.

Whether you are an experienced programmer or not, this website is intended for everyone who wishes to learn the Python programming language.

You are welcome to join our group on Facebook for questions, discussions and updates.

Just click on the chapter you wish to begin from, and follow the instructions. Good luck!

Learn the Basics

Data Science Tutorials

Advanced Tutorials

Other Python Tutorials

Contributing Tutorials

Read more here: Contributing Tutorials

This site is generously supported by DataCamp. DataCamp offers online interactive Python Tutorials for Data Science. Join over a million other learners and get started learning Python for data science today!

Python – How to split a String

Few examples to show you how to split a String into a List in Python.

1. Split by whitespace

By default, split() takes whitespace as the delimiter.

alphabet = "a b c d e f g"
data = alphabet.split() #split string into a list

for temp in data:
    print temp

Output

a
b
c
d
e
f
g

2. Split + maxsplit

Split by first 2 whitespace only.

alphabet = "a b c d e f g"
data = alphabet.split(" ",2) #maxsplit

for temp in data:
    print temp

Output

a
b
c d e f g

3. Split by #

Yet another example.

url = "mkyong.com#100#2015-10-1"
data = url.split("#")

print len(data) #3
print data[0]  # mkyong.com
print data[1]  # 100
print data[2]  # 2015-10-1

for temp in data:
    print temp

Output

3
mkyong.com
100
2015-10-1
mkyong.com
100
2015-10-1