Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7904865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:15:50+00:00 2026-06-03T10:15:50+00:00

I was reading about python functions and saw this code: def happyBirthday(person): print(Happy Birthday

  • 0

I was reading about python functions
and saw this code:

def happyBirthday(person):
    print("Happy Birthday to you!")
    print("Happy Birthday to you!")
    print("Happy Birthday, dear " + person + ".")
    print("Happy Birthday to you!")

happyBirthday('Emily')
happyBirthday('Andre')

I couldn’t understand why these brackets were being used
for the print commands and so I removed them.

def happyBirthday(person):
    print "Happy Birthday to you!"
    print "Happy Birthday to you!"
    print "Happy Birthday, dear " + person + "."
    print "Happy Birthday to you!")

happyBirthday('Emily')
happyBirthday('Andre')

Even after removing those brackets I am getting
the exact same results, so I am not sure which one is correct
or whether I should use those brackets at all.
Is it really necessary to use those brackets?

One more thing.
when I use the brackets then the +person+ gives
the result as Happy Birthday, dear Andre.
but when I use ,person, then it gives
the result as <‘Happy Birthday,dear ‘,’ ‘Andre’,’.’>

I am unable to understand these differences in the results.
Could you shed some light on this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T10:15:51+00:00Added an answer on June 3, 2026 at 10:15 am

    Is it really necessary to use those brackets?

    In Python 2.x, print is a statement, and the brackets are optional.

    In Python 3.x, print() is a function, and the brackets are mandatory.

    It is considered good practice to use brackets even in Python 2.x, to ease eventual transition to Python 3.x.

    I am unable to understand these differences in the results. Could you shed some light on this?

    Here is what happens when you print several comma-separated things in Python 2.x:

    In [1]: print(1,2,3)
    (1, 2, 3)
    

    The above is interpreted as the print statement followed by a single argument, which is a tuple. The tuple is rendered with parentheses and commas.

    In [2]: print 1,2,3
    1 2 3
    

    The above is interpreted as the print statement followed by three arguments. Each argument is printed out separately, with spaces between them.

    Neither version is great as far as compatibility with Python 3 is concerned: the first version is rendered differently, and the second is simply not valid Python 3 code.

    With this in mind, I recommend that you stick with:

    print("Happy Birthday, dear " + person + ".")
    

    This produces exactly the same results in both Python 2.x and Python 3.x.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Reading about Kohana templates and saw something I've never seen before: $this->template->title = __('Welcome
Reading about Django, I saw this: http://docs.djangoproject.com/en/1.1/ref/contrib/admin/#ref-contrib-admin - the fancy simple to use admin
I'm reading about the yield keyword in python, and trying to understand running this
I was reading about imports in python and came across this effbot article about
When I first started reading about Python, all of the tutorials have you use
I've been reading about Python's urllib2's ability to open and read directories that are
I have started to learn about python and is currently reading through a script
I was reading these days about large projects implementation in python and Flex, and
I know next to nothing about Python and I'm using scons. (if you're reading
I was reading some questions about not to use exec or eval in python

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.