Python String join() MethodThe join() strategy is an underlying technique in Python that has a place with the string class. Concatenating or joining elements from an iterable, like a list, tuple, or string, into a single string is what this method does. The join() technique takes the accompanying syntax. Basic Example: Let's look at an example to illustrate the usage of the join() method: Output: Hello World Python Programming The string "," which only contains one space character, is the basis for the call to the join() method in this example. There are four components in the iterable lis. The string "Hello World Python Programming" is created by concatenating the elements of lis with the separator "" using the join() method. The string is then output as a string. It allows various iterables like: List, Tuple, String etc. SignatureParametersiterable : iterable object like: List, Tuple, String etc. ReturnIt returns a new string or an exception TypeError if iterable contains any non-string value. Let's see some examples of join() method to understand it's functionalities. Python String join() Method Example 1A simple example which implements join() method with the List iterable, see the example below. Output: 1:2:3 Python String join() Method Example 2A list iterable join with empty string and produce a new string, see the example below Output: Javatpoint Python String join() Method Example 3An example of join() method with Set iterable. Set contains unordered elements and produce different output each times. See the example below. Output: Java->Python->C# Python String join() Method Example 4In case of dictionary, this method join keys only. Make sure keys are string, otherwise it throws an exception. Output: key1&key2 Next TopicPython Strings |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India