It’s because any iterable can be joined (e.g, list, tuple, dict, set), but its contents and the “joiner” must be strings.
For example:
'_'.join(['welcome', 'to', 'stack', 'overflow']) '_'.join(('welcome', 'to', 'stack', 'overflow'))
'welcome_to_stack_overflow'
Using something other than strings will raise the following error:
TypeError: sequence item 0: expected str instance, int found
Related Posts:
- How to convert list to string [duplicate]
- Why is it string.join(list) instead of list.join(string)?
- Python: Get the first character of the first string in a list?
- AttributeError: ‘list’ object has no attribute ‘replace’ when trying to remove character
- How to check if a string is a substring of items in a list of strings?
- AttributeError: ‘list’ object has no attribute ‘replace’ when trying to remove character
- AttributeError: ‘list’ object has no attribute ‘replace’ when trying to remove character
- How do I check if there are duplicates in a flat list?
- How to concatenate items in a list to a single string?
- Create nice column output in python
- How does str(list) work?
- Python cant convert ‘list’ object to str error [closed]
- How do I lowercase a string in Python?
- Difference between del, remove, and pop on lists
- Python – TypeError: ‘int’ object is not iterable
- Does Python have a string ‘contains’ substring method?
- IndexError: list index out of range and python
- How to read a file line-by-line into a list?
- Python – TypeError: ‘int’ object is not iterable
- Finding the index of an item in a list
- Best way to convert string to bytes in Python 3?
- What does the list() function do in Python?
- Why does this iterative list-growing code give IndexError: list assignment index out of range?
- ‘str’ object does not support item assignment
- Transpose/Unzip Function (inverse of zip)?
- Python: finding an element in a list [duplicate]
- How to avoid “RuntimeError: dictionary changed size during iteration” error?
- Convert bytes to a string
- How to print like printf in Python3?
- How to read a text file into a string variable and strip newlines?
- Writing a list to a file with Python
- How do I concatenate two lists in Python?
- if else in a list comprehension
- How can I randomly select an item from a list?
- Get unique values from a list in python [duplicate]
- Fastest way to check if a value exists in a list
- How can I count the occurrences of a list item?
- How do I concatenate two lists in Python?
- if else in a list comprehension
- Python set to list
- Split string with multiple delimiters in Python [duplicate]
- How to find all occurrences of an element in a list
- How to find all the indexes of a recurring item in a list?
- How to find all occurrences of a substring?
- python – if not in list
- How do I concatenate two lists in Python?
- Replace values in list using Python
- Python TypeError: not enough arguments for format string
- What does the ‘b’ character do in front of a string literal?
- Check string “None” or “not” in Python 2.7
- Get unique values from a list in python
- ‘list’ object has no attribute ‘shape’
- What does the ‘b’ character do in front of a string literal?
- Best way to replace multiple characters in a string?
- How to convert string to binary?
- How do I find the duplicates in a list and create another list with them?
- Convert hex to binary
- TypeError: unsupported operand type(s) for -: ‘list’ and ‘list’
- Remove all occurrences of a value from a list?
- Python return list from function
- Remove all special characters, punctuation and spaces from string
- In Python, when to use a Dictionary, List or Set?
- Whats the difference between ‘for x in list:’ and ‘for x in list[:]:’
- Removing Punctuation From Python List Items
- Check if two unordered lists are equal
- How can I compare two lists in python and return matches
- ValueError: cannot index with vector containing NA / NaN values
- How to append multiple values to a list in Python
- How do you split a list into evenly sized chunks?
- How to check if type of a variable is string?
- How do I format a string using a dictionary in python-3.x?
- Removing numbers from string
- How to read a text file into a list or an array with Python
- Map to List error: Series object not callable
- How to find char in string and get all the indexes?
- How can I create an array/list of dictionaries in python?
- How to sort a list/tuple of lists/tuples by the element at a given index?
- How can I check if character in a string is a letter? (Python)
- How to multiply all integers inside list
- Find the nth occurrence of substring in a string
- How to convert ‘binary string’ to normal string in Python3?
- Python: Converting string into decimal number
- How to remove square brackets from list in Python?
- Logical indexing with lists
- Split string using a newline delimiter with Python
- Remove specific characters from a string in Python
- creating a reverse method for a python list from scratch
- Turn a single number into single digits Python
- How to create a list of objects?
- In Python, is there an elegant way to print a list in a custom format without explicit looping?
- Circular list iterator in Python
- How is Python’s List Implemented?
- How can I check if a string contains ANY letters from the alphabet?
- Create a list with initial capacity in Python
- Python initializing a list of lists
- Find index of last occurrence of a substring in a string
- Python convert tuple to string
- Does Python have an immutable list?
- TypeError: coercing to Unicode: need string or buffer