Non strict strings comparison.With '=' instead '==' like AutoIT

It’s amazing how it would help us developers to add a function that avoids this strict uppercase/lowercase comparison.

Example:

if 'test' = 'Test':
    print('pass')

It would be equivalent to if str(a).lower() == str(b).lower(). It would have various useful uses such as comparing users in a database and it is a comparison that is not used by anything today. It has been tested for years in AutoIT and has not caused any problems.

Ultimately, a programming language (especially when it comes to scripting) should be philosophically close to humans and not to a stubborn person. Words have the same meaning for humans whether they are capitalized or lowercase.

Even if my proposal seems like crap to you or there is some function that does this and I didn’t see it (I really find it hard to believe that this can’t be done natively), I invite you to participate and give your opinion.

The idea might be worth discussing, but you’re going to have to find a different syntax. ‘=’ is reserved for assignment in Python.

1 Like
>>> if 'Hola' = 'hola':
  File "<stdin>", line 1
    if 'Hola' = 'hola':
       ^^^^^^
SyntaxError: cannot assign to literal here. Maybe you meant '==' instead of '='?

Let’s keep in mind that paradoxically Python is used in data analysis, as a graduate in data analysis this would be extremely useful to me.

I understand, it is complicated, perhaps we could use another operator, we could review other languages.

Or simply incorporate a native function to compare strings in a flexible way. Sometimes we come across Unicode characters with accents and weird stuff. These are difficult to compare without filtering them first and it is practically impossible to solve for a person initiated in a high-level language like this.

You must be trolling … differentiation between assignment command and comparison is one cleanest signs of difference between lower quality toy-like languages (e.g., Visual Basic) and real ones.

5 Likes

This is not about trolling, this is not a game, this is a real experience. Let me make it clear that I don’t like Visual Basic and stuff like that at all and you don’t have to attack me. I’ve been programming since I was 6, I’ve been working since I was 18, I’m 27. I’ve never touched Visual Basic.

I must admit, though, that you are somewhat right. :joy:

Adding stricter comparison like in JavaScript might have a greater chance:

>>> 0 == 0.0
True
>>> 0 === 0.0
False
1 Like

I understand, it looks nice and I actually thought about it, but that way would break the current code.

I think if we just used ‘=’ it would be even less damaging in the short term.

Calling it “amazing” and “crap” by turns is a poor way to start discourse. Ideas should stand on their own merits. It is a mistake, which is neither of those things.
x.lower() == y.lower() is readable, succinct, and explicit. That’s the bar to beat, and this suggestion doesn’t come close.

I believe that you are failing to ask some of the important questions. Let me see if I can get you started in the right direction…

  • My use case is special to me. But what is the broader community seeing. Is my case common? Do other developers find it difficult to handle?

  • What is the general form of my use case? If my case involves str, what about int, dict, list, bool, tuple, float, and bytes? What about user-defined classes?

  • Am I making the meaning of things more or less clear?


As I see it, this proposal is dead on arrival. This sort of idea, which adds some arcane use of symbols[1] in place of well-named functions, tends to draw out unfavorable comparisons to perl or other languages. If you want to understand why, the summary is: Python prizes readability very highly.

You should interrogate your ideas a bit more. When you propose an idea, you’re asking a bunch of strangers to read what you have written. Syntax changes are not made lightly or easily. Suggesting such changes without careful up-front effort to present the idea well is a poor use of time. The better you spend your readers’ time, the more likely they are to engage in the thread and have a productive debate.


  1. In this case, single = in an expression. It’s subtle for a variety of reasons. ↩︎

7 Likes

The time you took to respond shows that you really liked something about my proposal, so I appreciate it.

No, I think this proposal is awful. But I want you to learn why it’s awful.
Simply saying “it’s awful” and walking away is rude to you in the extreme and a disservice to you and the community.

6 Likes

I understand that big changes are difficult for the people.

I saw that. Could you take a moment to read the code of conduct?

3 Likes