How to print percentage sign(‘%’) in Python
In this tutorial, we will learn how to print a percentage sign (‘%’) in Python.
‘%’ sign also denotes modulo operator (a%b) which returns the remainder as
when ‘a’ is divided by ‘b’.
Also, ‘%’ is an ASCII symbol which has an ASCII value of ’37’
Now let us code our solution.
Print percentage sign in Python
The first method is to store the symbol in string format and then
use the print function to print as shown in the below.
var = "%" print(var)
The other method is through the ascii value of the symbol
Let us find out the ascii value of the symbol
var = ord('%') print("The ascii value of % is " + var) # ASCII value for any charater is found using ord() function # which has got argument of type "string" and return type is INTEGER
The ascii value of % is 37
print(chr(37)) #chr() is a in-built function in python which is used to convert #ascii values to their respective symbols or characters
ASCII value 37 denotes ‘%’ symbol
Hope this tutorial helps you to learn how to print percentage “%” symbol in Python.
You may also read:
- How to print string and int in the same line in Python
- How to escape from \n newline character in python