In Python Programming some time we face a scenario to concatenate string. We know, two join two strings we will use the '+' operator in many programming examples.
Today we are going to learn how to concatenate strings in a python program.
Let's get started.
We have a simple python program with two string variable like below
# Python program with Strings |
Output
Python |
Concatenate String in Python
Now how we will concatenate these two strings.
Python we have below ways to concatenate String
Using + operator
Using the '+' operator we can concatenate multiple strings in python. With the '+' operator it is an easy way we can join the string. To use this '+' operator both variables should be a String.
# Python program with Strings var3 =var1+var2 |
Output:
It will print Python Strings
Using % Operator
This is a String Formatter operator. With the '%' operator we can format any string.
# Python program with Strings # % Operator is used here to combine the string |
Using join() method
The string contains a method called join() which will join the one string with other string values.
# Python program with Strings # A variable var1 having the value python var3="".join([var1,var2]) |
Using format()
# Python program with Strings # A variable var1 having the value python # format function is used here to |
Output:
Python Strings
Know more python course for beginner
Python Remove Last Character From String
Tags: Python Strings, String Concatenation, String join, format
Article Contributed By :
|
|
|
|
1056 Views |