So I was looking at a python tutorial, and in a statement, it used %.
print ("Total Employee %d" % Employee.empCount)
Can someone please take their time and describe to me what that means. I'm pretty sure that it doesn't signify a division.
So I was looking at a python tutorial, and in a statement, it used %.
print ("Total Employee %d" % Employee.empCount)
Can someone please take their time and describe to me what that means. I'm pretty sure that it doesn't signify a division.
Python uses C-style string formatting to create new, formatted strings. The "%" operator is used to format a set of variables enclosed in a "tuple" (a fixed size list), together with a format string, which contains normal text together with "argument specifiers", special symbols like "%s" and "%d".
the % sign in this case is supposed to be used for string formatting. This is an old technique and can be used with and f-string now. % is mostly used in java and not python.
Python Program for Old Style Formatting of Integers also used %
Integer1 = 12.3456789
print("Formatting in 3.2f format: ")
print('The value of Integer1 is %3.2f' %Integer1)
print("\nFormatting in 3.4f format: ")
print('The value of Integer1 is %3.4f' %Integer1)
Output:
Formatting in 3.2f format:
The value of Integer1 is 12.35
Formatting in 3.4f format:
The value of Integer1 is 12.3457
also use as
print("writing integer in a string: %s" %Integer1)
output
writing integer in a string: 12.3456789
% Employee.empCount
is a variable and %d
for print integer variable.That's mean value of variable % Employee.empCount
print in place of %d
.
% sign use for give reference of variable.