print() is showing quotation marks in results

前端 未结 1 926
轻奢々
轻奢々 2020-12-21 07:16

When the below portion of the script is activated, it shows all the commas and single quotes (and parentheses) in the results.

print(name, \'has been alive          


        
相关标签:
1条回答
  • 2020-12-21 08:00

    You need from __future__ import print_function.

    In Python 2.x what you are doing is interpreted as printing a tuple, while you are using the 3.x syntax.

    Example:

    >>> name = 'Ryan'
    >>> days = 3
    >>> print(name, 'has been alive for', days, 'days.')
    ('Ryan', 'has been alive for', 3, 'days.')
    >>> from __future__ import print_function
    >>> print(name, 'has been alive for', days, 'days.', sep=', ')
    Ryan, has been alive for, 3, days.
    
    0 讨论(0)
提交回复
热议问题