operator in print statement

0 votes

My question is about the syntax in the print statement:

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

blank = Point
blank.x = 3.0
blank.y = 4.0    
print('(%g,%g)' % (blank.x,blank.y))

This print statement simply prints (3.0, 4.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?

Any help will be appreciated

Nov 15, 2018 in Python by Jino
• 5,820 points
2,240 views

1 answer to this question.

0 votes

'(%g,%g)' is the template and (blank.x,blank.y) are the values which need to be filled in place of %g and %g and % operator does just that. Its called String interpolation or formatting operator.

answered Nov 15, 2018 by findingbugs
• 3,260 points

Related Questions In Python

0 votes
0 answers

Python: % operator in print() statement

I just came across this Python code, ...READ MORE

Apr 18, 2022 in Python by Edureka
• 13,620 points
637 views
0 votes
2 answers

Unable to use print statement in python3

print will work when you use print("Your ...READ MORE

answered Feb 14, 2019 in Python by Shashank
• 1,370 points
1,308 views
0 votes
3 answers

how to use print statement in python3?

Brackets are required to print the output. >>> ...READ MORE

answered Nov 25, 2021 in Python by anonymous
1,660 views
0 votes
1 answer

% operator in Python

When you use '(%g,%g)', it is the ...READ MORE

answered Nov 12, 2018 in Python by ana1504.k
• 7,910 points
1,010 views
0 votes
0 answers

what is a bitwise operator in python?

can you show some operations using bitwise ...READ MORE

Apr 8, 2019 in Python by Waseem
• 4,540 points
500 views
0 votes
0 answers

what is the logical AND operator in python?

how do i use it in a ...READ MORE

Apr 12, 2019 in Python by Waseem
• 4,540 points
545 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,478 views
0 votes
2 answers

How to implement Stack in python

There are different method to implement stack ...READ MORE

answered Jun 21, 2020 in Python by pagarsach
• 160 points
1,378 views
0 votes
1 answer

How to write to CSV line by line in python

The simple way of doing this will ...READ MORE

answered Nov 15, 2018 in Python by findingbugs
• 3,260 points
5,699 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP