Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5978757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:33:46+00:00 2026-05-22T21:33:46+00:00

Possible Duplicate: Python '==' vs 'is' comparing strings, 'is' fails sometimes, why? I am

  • 0

Possible Duplicate:
Python '==' vs 'is' comparing strings, 'is' fails sometimes, why?

I am going to skip the part where i tell you how i tested my code and jump straight to the problem.

Python seems to be having some problem matching split of a unicode string to another inline unicode string in an if statement.

>>>zone = u'domain.com.'
>>>zone[-1:]
u'.'

>>>u'.' is u'.' #works fine
True
>>> z[-1:] == u'.' #works fine
True
>>> zone[-1:] is u'.' # FAILS !
False

here is my actual code snippet

>>>if zone[-1:] is not u'.':
>>>    #this line will always run !

if i change ‘is not’ to != the code works fine !

Does anyone know why “is” caused the comparison to fail ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:33:46+00:00Added an answer on May 22, 2026 at 9:33 pm

    It’s because strings are objects in Python — when you slice a string, you create a new one.

    It’s slightly more complicated than that, but that’s the gist of it.

    Solution: use == and != instead of is and is not.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Python ‘==’ vs ‘is’ comparing strings, ‘is’ fails sometimes, why? In Python,
Possible Duplicate: Python ‘==’ vs ‘is’ comparing strings, ‘is’ fails sometimes, why? Is a
Possible Duplicate: Python '==' vs 'is' comparing strings, 'is' fails sometimes, why? Hi. I
Possible Duplicate: Choosing Java vs Python on Google App Engine We are going to
Possible Duplicate: Call Python From PHP And Get Return Code probably a very stupid
Possible Duplicate: comparing contents of two files using python I have a file name
Possible Duplicate: Ternary conditional operator in Python If I have some code like: x
Possible Duplicate: Python: sort a part of a list, in place I want to
Possible Duplicate: Python float - str - float weirdness I run the following code
Possible Duplicate: Python replace multiple strings I am looking to replace , \r ,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.