[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Why does print("Miles per gallon:", mpg) return this
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 8
Thread images: 1
File: 138380053358[1].jpg (102 KB, 500x381) Image search: [Google]
138380053358[1].jpg
102 KB, 500x381
Why does

print("Miles per gallon:", mpg)

return this ('Miles per gallon:', 2.0)

instead of Miles per gallon: 2.0

??
>>
It's the console's way of representing a string vs not string
>>
>>54934087
What fucking language
>>
>>54934132

my apologies.. Python
>>
>>54934138
python 3?
works fine on my machine:

>>> mpg=2.0
>>> print("Miles per gallon:", mpg)
Miles per gallon: 2.0
>>
>>54934174

I believe I'm running Python 2.7.10
>>
>>54934185
Then get rid of the parentheses. In python2, print is a keyword and is used without parens. So what you're telling the interpreter is to print out a tuple with the members "Miles per gallon" and 2.0, which is exactly what it's doing

[spoiler]Also switch to python3, python2 is dying and there's no reason to learn it except to support legacy code[/spoiler]
>>
>>54934226

excellent. thank you. I will update to 3.5.1 now.
Thread replies: 8
Thread images: 1

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.