Mahmudul Alam
Mahmudul Alam

Reputation: 153

Why Python "is" operator gives different result for variable containing same string

When i am trying to compare the identity of two variable containing same string, python gives me different result.

msg = "hello world"
new_msg = "hello world"

print( msg is new_msg )
> False

But,

msg = "hello_world"
new_msg = "hello_world"

print( msg is new_msg )
> True

Upvotes: 0

Views: 36

Answers (0)

Related Questions