How To Add Period In Python

How To Add Period In Python | Here, in the following article, we will discuss how to add a period after a variable in Python programming language. So, firstly we will discuss what is a period in a python programming language.

In Python programming language, a period accesses methods (functions) and properties (data) of objects. We can “add” (concatenate) the period character to the end of the string. For example: “John is learning Python” + “!” # This code returns “John is learning Python!”

How to Add a Period After a Variable in Python

i = 5
print("i is equal to", i, ".")

Output:-

i is equal to 5.

In the above example, we can use string formatting to add a period.

i = 5
print("i is equal to %d." % i)

Strings have a .format() function that can be used for adding a period.

i = 5
print("i is equal to {}".format(i))

It’s useful if we have a placeholder that’s used multiple times in the format string.

i = 5
print("i={0}, i.e. 'i is equal to {0}.'".format(i))

Output:-

i=5, i.e. ‘i is equal to 5.’

We can also concatenate it like this,

print("i is equal to " + str(i) + ".")

Here, we have discussed how to add a period after a string or a variable. Hope you all find the article useful.

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!

Leave a Comment

Your email address will not be published. Required fields are marked *