is
is identity testing, ==
is equality testing. what happens in your code would be emulated in the interpreter like this:
>>> a="pub"
>>> b = ''.join(['p', 'u', 'b'])
>>> a == b
True
>>> a is b
False
so, no wonder they’re not the same, right?
In other words: a is b
is the equivalent of id(a) == id(b)
Related Contents:
- String comparison in Python: is vs. == [duplicate]
- double equals vs is in python [duplicate]
- How are strings compared?
- Why does the “is” keyword have a different behavior when there is a dot in the string?
- How do I concatenate (join) items in a list to a single string?
- How to get a function name as a string?
- Split Strings into words with multiple word boundary delimiters
- Is there a difference between “==” and “is”?
- Alphabet range in Python
- Proper indentation for multiline strings?
- Create Pandas DataFrame from a string
- str.startswith with a list of strings to test for
- Can’t compare naive and aware datetime.now()
- How do I convert a string to a double in Python?
- Wrap long lines in Python [duplicate]
- Python csv string to array
- Removing a list of characters in string
- How to change the datetime format in Pandas
- Case insensitive ‘in’
- Using multiple arguments for string formatting in Python (e.g., ‘%s … %s’)
- write() versus writelines() and concatenated strings
- Why doesn’t calling a string method (such as .replace) modify (mutate) the string? Why doesn’t it change unless I assign the result?
- Test a string for a substring [duplicate]
- Is there a generator version of `string.split()` in Python?
- Strip spaces/tabs/newlines – python
- Iterate over the lines of a string
- How to write string literals in python without having to escape them?
- Confused about __str__ on list in Python [duplicate]
- Printing without newline (print ‘a’,) prints a space, how to remove?
- Should __ne__ be implemented as the negation of __eq__?
- How do I wrap a string in a file in Python?
- Python – difference between two strings
- How to determine whether a substring is in a different string [duplicate]
- Why is f'{{{74}}}’ the same as f'{{74}}’ with f-Strings?
- How to get ° character in a string in python?
- Remove Last Path Component In a String
- Converting a string representation of a list into an actual list object [duplicate]
- What’s the difference between str.isdigit(), isnumeric() and isdecimal() in Python?
- Why doesn’t calling a string method (such as .replace or .strip) modify (mutate) the string?
- How to downcase the first character of a string?
- Determining how many times a substring occurs in a string in Python
- Detect whether a Python string is a number or a letter [duplicate]
- Why are Python strings immutable? Best practices for using them
- Random byte string in Python
- Replace \n with [duplicate]
- How to check for palindrome using Python logic
- Equivalent of Python string.format in Go?
- What is a clean way to convert a string percent to a float?
- String to list in Python
- How to match any string from a list of strings in regular expressions in python?