Difference between %s and %d in python string formatting??

0 votes
I want to know, what is %s and %d and how do they work??
May 28 in Python by Taj
• 560 points
7 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

%s and %d are used for string formatting where %s and %d holds place for a string and a number respectively, and their associated values are passed using a tuple with % operator.

Input:

name = 'Cody'
age = 22
print ('%s %d' % (name, age))

Output:

Cody 22

answered May 28 by Shabnam
• 400 points

Related Questions In Python

+1 vote
1 answer

What is the difference between range and xrange functions in Python 2.X?

xrange only stores the range params and ...READ MORE

answered Aug 22, 2018 in Python by Priyaj
• 56,140 points
92 views
+1 vote
1 answer

What's the difference between eval, exec, and compile in Python?

exec is not an expression: a statement ...READ MORE

answered Aug 28, 2018 in Python by Priyaj
• 56,140 points
338 views
0 votes
1 answer

Difference between module and Package in Python

A module is basically a single file ...READ MORE

answered Nov 13, 2018 in Python by SDeb
• 10,860 points
78 views
0 votes
1 answer

In Python, what is difference between Array and List?

Lists and arrays are used in Python ...READ MORE

answered Mar 15 in Python by Taj
• 560 points

edited Mar 18 by Omkar 281 views
+4 votes
6 answers
0 votes
1 answer

Removing surrounding whitespace

Try the strip() function:  s = s.strip() If you ...READ MORE

answered May 4, 2018 in Python by Nietzsche's daemon
• 4,260 points
30 views
0 votes
1 answer

How to add a new Python interpreter in PyCharm?

Refer to the below screenshots: Then set a ...READ MORE

answered May 30 in Python by Shabnam
• 400 points
36 views
0 votes
1 answer

How to install modules in Pycharm?

You can install modules in PyCharm using ...READ MORE

answered May 30 in Python by Shabnam
• 400 points
74 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.