Strings concatenation and Formatting in Python

Strings concatenation and Formatting in Python is the process for joining small string to make the bigger. For example, you can create a full name by joining two string like Firstname and Lastname. Formatting will help to display variable in or end of the string.

Strings Concatenation in Python

Python provides the easy way to concatenate Strings by using + (plus)  and * (star) Sign. There are other methods such as append(), join() and format().

Using + 

+ will adds values on either side of the operator

Here is an example :

Using *

*  Creates new strings, concatenating multiple copies of the same string.

Here is an example :

String Formatting in Python

You might have the experience to use C language to print String and Integer using %s and %d. Python has similar string formatting to create new, formatted strings. The % operator is used to format variables.

Here are the examples:

String formatting using two and more than values using the tuple. A tuple is a sequence of immutable Python objects. Tuples use parentheses.

Python is supporting other function like append and join to manipulate String data.

Leave a Reply