%  string formatting operator

% is a string formatting operator in Python. Refer to the following example:

#!/usr/bin/python3
print ("Hello this is %s and my age is %d !" % ('John', 25))


Output:
Hello this is John and my age is 25 !

The following table shows a list of symbols used along with %:

S.No.

Format symbol and conversion

1

%c – character

2

%s – string conversion via str() prior to formatting

3

%i – signed decimal integer

4

%d – signed decimal integer

5

%u – unsigned decimal integer

6

%o – octal integer

7

%x – hexadecimal integer (lowercase letters)

8

%X – hexadecimal integer (uppercase letters)

9

%e – exponential notation (with lowercase e)

10

%E – exponential notation (with uppercase E)

11

%f – floating point real number

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset