Do you need to split and join your strings on various separators? Python provides simple methods for splitting and joining strings in a number of useful ways.
- [Instructor] Python allows you…to easily split and join strings…based on separator characters.…Here's how this works.…Here in Komodo I've opened a working copy…of split-join.py from chapter 11…of the exercise files, and here we have…a string with a bunch of words in it.…I can easily split this into a list like this,…and when I run this, you see our result is a list…with each element as a separate word…from the string.…So what Python has done here…is it's folded all the spaces,…and then split the string on the spaces,…and loaded up a list with each of the individual words.…
And so I can add as many spaces as I want here.…In fact, I can even add new lines,…and so we'll make this the triple quote,…and I'll just add a new line there,…and one there, and when I run this…you see we get exactly the same result…because what Python has done…is taking all those spaces and newlines…and it's folded them all together…before splitting it.…And so this the default behavior of split.…It's how must people will usually use it,…and, of course, you can change it.…
- Python anatomy
- Types and values
- Conditionals and operators
- Building loops
- Defining functions
- Python data structures: lists, tuples, sets, and more
- Creating classes
- Handling exceptions
- Working with strings
- File input/output (I/O)
- Creating modules
- Integrating a database with Python db-api
Skill Level Intermediate
Python: Programming Efficientlywith Michele Vallisneri2h 15m Intermediate
2. Language Overview
3. Types and Values
8. Structured Data
11. String Objects
12. File I/O
13. Built-in Functions
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.