Python Forum
i need assistance on the output of a particular code - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: i need assistance on the output of a particular code (/thread-10409.html)



i need assistance on the output of a particular code - sirvinprogramming - May-19-2018

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


RE: i need assistance on the output of a particular code - j.crater - May-19-2018

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?


RE: i need assistance on the output of a particular code - sirvinprogramming - May-19-2018

[quote="j.crater" pid="47631" dateline="1526736673"]This particular code sample is pretty simple, but
I want the commas, apostrophes and Bracket removed.


RE: i need assistance on the output of a particular code - buran - May-19-2018

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