How do I concatenate strings in Python?

There are several ways to concatenate strings in Python. The plus ("+") operator is the most basic and widely used method to concatenate strings, but it only works with strings. To concatenate strings and numbers, use the modulus ("%") operator. To concatenate list items to a string, you use string.join() method. To concatenate several variables to a string and format the result string, use the string.format() method. The new Python 3.6 f-strings are similar to string.format(), but is more concise, easier to read, and less error-prone when refactoring your code. In this Python Concatenate Strings example, we use the "+" operator to concatenate two strings. The rest of Python's string concatenation methods are listed below, with detailed explanations and examples. Click Execute to run the Python Concatenate Strings example online and see the result.
Loading...