Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between variable and print variable [duplicate]

Tags:

python

I have the following code (Assuming I am typing in IDLE line by line)

# -*- coding: utf-8 -*-
s = u"My Currency is - £"
s
print s

for - s - I'm getting an output - u'My Currency is - \xa3'

for - print s - I'm getting an output - u'My Currency is - £'

What is the difference ? Why I am getting different outputs ?

like image 505
Kartheek Palepu Avatar asked May 24 '26 08:05

Kartheek Palepu


1 Answers

In Python, print shows the result of __str__ on its arguments, which may be different from __repr__. For more, see here: Difference between __str__ and __repr__ in Python

like image 70
John Zwinck Avatar answered May 26 '26 21:05

John Zwinck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!