Python Print variable and string in same line

+1 vote

The problem is on my last line. How do I get a variable to work when I'm printing text either side of it?

Here is my code:

currentPop = 12346
oneYear = 365
hours = 24
minutes = 60
seconds = 60

# seconds in a single day
secondsInDay = hours * minutes * seconds

# seconds in a year
secondsInYear = secondsInDay * oneYear

fiveYears = secondsInYear * 5

#Seconds in 5 years
print fiveYears

# fiveYears in seconds, divided by 7 seconds
births = fiveYears // 7

print "If there is a birth every 7 seconds, there would be: " births "births"

Oct 30, 2018 in Python by findingbugs
• 3,260 points
1,555 views

1 answer to this question.

0 votes

For a better understanding you can refer the following link string formatting:

Use comma (,) to separate strings and variables while printing: eg

print "If there is a birth every 7 seconds, there would be: ",births,"births"

, in print statement separtes the items by a single space:

>>> print "abc","bcd","def"
abc bcd def
answered Oct 30, 2018 by Priyaj
• 58,020 points

Related Questions In Python

0 votes
1 answer

Is it possible to print a string and a variable in a single print statement in Python?

This can be done using simple string ...READ MORE

answered Jul 15, 2019 in Python by Neel
• 3,020 points
861 views
+1 vote
2 answers

How to print first character of each word in upper case of a string in Python

class Solution:     def firstAlphabet(self, s):             self.s=s              k=''              k=k+s[0]              for i in range(len(s)):                     if ...READ MORE

answered Oct 28, 2020 in Python by Anurag
12,431 views
0 votes
1 answer

What's the right way to concatenate files and appending the New Line character in Python? Text or binary mode?

It seems like you're using the wrong ...READ MORE

answered Nov 13, 2018 in Python by Anirudh
• 2,090 points

edited Dec 14, 2018 by Anirudh 1,702 views
0 votes
1 answer

comparing strings in Python using "==" or "is"

is is used for identity testing and ...READ MORE

answered Sep 19, 2018 in Python by SDeb
• 13,300 points
857 views
0 votes
1 answer

Print Delimited list

You can try the following and see ...READ MORE

answered Feb 28, 2019 in Python by SDeb
• 13,300 points
881 views
0 votes
2 answers
0 votes
1 answer

How can I print variable and string on same line in Python?

Use , to separate strings and variables while printing: print ...READ MORE

answered Sep 17, 2018 in Python by Priyaj
• 58,020 points
3,537 views
0 votes
1 answer

*args and **kwargs in python

In cases when we don’t know how ...READ MORE

answered Jul 20, 2018 in Python by Priyaj
• 58,020 points
843 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