Python Forum

Full Version: i need assistance on the output of a particular code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
def sentence(subject="i", predicate="play", object="football"):
    print(subject, predicate, object)

sentence()
Output:
('i', 'play', 'football')
please I just started coding a month ago I need an assistant on why this code I executed "i play football" displayed the comma's and apostrophes sign
This particular code sample is pretty simple, but next time make sure to use Python code tags. You can find help here.

By default print will display whitespace delimited input arguments by default, if you don't provide different formatting rules/arguments. What is the desired outcome you want instead?
[quote="j.crater" pid="47631" dateline="1526736673"]This particular code sample is pretty simple, but
I want the commas, apostrophes and Bracket removed.
what you supply to print functions is in fact tuple. So it prints tuple
you must learn string formatting
def sentence(subject="i", predicate="play", object_="football"):
    print('{} {} {}'.format(subject, predicate, object_))
 
sentence()
or you can use join method
def sentence(subject="i", predicate="play", object_="football"):
    print(' '.join([subject, predicate, object_])
 
sentence()
in python 3.6+ you can use the new f-strings
def sentence(subject="i", predicate="play", object_="football"):
    print(f'{subject} {predicate} {object_}')
 
sentence()
finally, note that I replaced object with object_, because object is builtin and you are overshadowing it which will bring problems