python 3.x - remove "()" "," and " ' " from a function output..Python3 -
first off, here's code. (still new in function creating)
function testing!!
def userinfo(name, age, birth): """read doing userinfo__doc__""" print("name:",name) print("age:",age) print("birth:",birth) return n_input=input("name?>> ") a_input=int(input("age?>> ")) b_input=input("birth date?(mm dd yyyy)>> ") userinfo(n_input, a_input, b_input)
codeoutput
('name:', 'jaymz') ('age:', 25) ('birth:', '02 26 1991')
the int portion of code outputs no " ' " (which knew) still "()" , ","... string portion outputs stuff don't want surrounding output... how rid of in code?(i learn seeing other code first on how people it)
ps. brainfart?.... have "format" on output code? or format numbers?
you output because you're using python 2.x. python 2 thinks you're printing tuple
. python 3 issue want.
as jojonas suggested, using from __future__ import print_function
works versions. you're not able use print
without parentheses after importing that, best.
but ...
to treat cases, use format
instead (using {}
indicate location of string insert):
def userinfo(name, age, birth): """read doing userinfo__doc__""" print("name: {}".format(name)) print("age: {}".format(age)) print("birth: {}".format(birth))
note: works not powerful:
print("name: "+name) # need `str` integer, ex `str(age)` print("name: %s" % name) # old-style formatting
Comments
Post a Comment