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
• 1,040 points
34 views

1 answer to this question.

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
• 920 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,900 points
239 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,900 points
576 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
• 13,160 points
121 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
• 1,040 points

edited Mar 18 by Omkar 4,260 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
44 views
+1 vote
1 answer

How to check if a string is in a file, using python?

Hi, Try the below given code: with open('myfile.txt') as ...READ MORE

answered Jul 4 in Python by Shabnam
• 920 points
43 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
• 920 points
599 views