Reputation: 27
upper() Return Value
upper() method returns the uppercase string from the given string. It converts all lowercase characters to uppercase. If no lowercase characters exist, it returns the original string.
If it is so then why their id's are not same since upper here is returning the original string to y?
x = 'PYTHONCORE'
y = x.upper()
print(id(y), id(x))
Output:
1925088550320 1925088583152
Upvotes: 0
Views: 34
Reputation: 9731
The Python documentation for the .upper
method states:
“Return a copy of the string with all the cased characters converted to uppercase.”
Note: A copy of the string, therefore different objects with different memory addresses. Problem solved.
Upvotes: 2