4.2.12 Creating Lists from Strings: split()

Unit: Unit 4: Strings, Lists, and Tuples • Interactive Practice

Quick Answer & Summary:

Interactive Python programming tutorial and practice in your browser.

Interactive Challenge (Run Live in Browser):

# Split log strings and delimited records into structured lists
csv_row = "item_101,Mechanical Keyboard,99.50,In Stock"
sentence = "Python makes data parsing fast and intuitive"

# 1. Split CSV row by comma delimiter ','
fields = csv_row.split(",")

# 2. Split sentence by whitespace (default)
words = sentence.split()

print("CSV fields:", fields)
print("Word count:", len(words))
print("First word:", words[0], "| Last word:", words[-1])
Open in Live Interactive Python Sandbox →