% operator in Python

0 votes
In the following Code:

class Point(object):
    """blub"""
    #class variables and methods

blank = Point
blank.x = 2.0
blank.y = 6.0    
print('(%g,%g)' % (blank.x,blank.y))

It prints (2.0, 6.0), i.e. the values in blank.x and blank.y.

I don't understand the % operator in front of the (blank.x, blank.y) in the last line. What does it do and where can I find it in the documentation?
Nov 12, 2018 in Python by Sayantini
• 140 points
11 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes
When you use '(%g,%g)', it is the template and (blank.x,blank.y) are the values which need to be filled in place of  %g and %g and % operator is used to perform the same. It is called interpolation or formatting operator.
answered Nov 12, 2018 by ana1504.k
• 5,950 points

Related Questions In Python

0 votes
1 answer

What are the ternary conditional operator in Python?

The Ternary Conditional operator was added in ...READ MORE

answered Sep 19, 2018 in Python by SDeb
• 9,460 points
24 views
0 votes
1 answer

How does % work in Python?

The % (modulo) operator yields the remainder ...READ MORE

answered Oct 10, 2018 in Python by SDeb
• 9,460 points
12 views
0 votes
1 answer

% operator in print() statement

'(%g,%g)' is the template and (blank.x,blank.y) are the values which ...READ MORE

answered Nov 15, 2018 in Python by findingbugs
• 3,140 points
11 views
0 votes
1 answer

How to use not equal operator in python

Use !=. See comparison operators. For comparing object identities, ...READ MORE

answered Dec 20, 2018 in Python by charlie_brown
• 7,710 points
59 views
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
19 views
0 votes
1 answer

Power Math in Python

When you use "^" operator, it is ...READ MORE

answered Nov 12, 2018 in Python by ana1504.k
• 5,950 points
16 views
0 votes
1 answer

Access Webcam using Python?

OpenCV has support for getting data from ...READ MORE

answered Oct 17, 2018 in Python by ana1504.k
• 5,950 points
150 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.