join()
A string method that glues a list of strings together with the string it is called on between them.
In more detail
", ".join(["a", "b", "c"]) gives "a, b, c". It is roughly the reverse of split. Every item must already be a string, so convert numbers first, for example with a comprehension.
Example
"-".join(["2026", "09", "29"])Related terms
- split() — A string method that cuts a string into a list of parts, at white space by default or at a separator you give.
- separator — The string placed between items when they are joined, or removed between parts when a string is split.
- string method — A method that belongs to strings, such as upper, lower, count, find, replace, split, strip, startswith or join.
Taught in
- Input, And Numbers Versus Digits — Hands-on Python: Complete Video Course & Book
- The String Format Method — Hands-on Python: Complete Video Course & Book
- Returning Values — Hands-on Python: Complete Video Course & Book
- Split And Join — Hands-on Python: Complete Video Course & Book
- Compound Boolean Expressions — Hands-on Python: Complete Video Course & Book
- Strings: Escapes, Slices And Methods — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Comparing, Slicing And Never Changing — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- String Methods The Exam Picks — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Twelve Traps, Mostly Objects — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Mock, Review And Exam Day — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep