I have divided this article into 4 levels as shown below. I urge you to call on your “virtue of patience” for another 15mins and read on! I promise you will learn a thing or 2 as we have merely scratched the surface! If you feel you have learned everything there is to know about the “=” operator, then hold your horses! There is plenty more to learn! In simple words, if objects on either side of the “=” operator have the same value we get True and if they have different values we get False 3rd line says “is 1 equal to 1” and we get True.1st line says “is 1 equal to 2?” and we get False.In this session at the Python interpreter, Here is a simple example Using ‘=’ to check if 2 integer objects are equal to each other > 1 = 2 You may ask why the language designers used ‘=’ instead of ‘=’?, that’s because of the way the computer languages evolved, and it makes sense as the assignment operators occur more frequently in computer programs compared to equality checks! How does the “=” operator compare with the “=” operator in Python? The single equal sign “ =” is the assignment operator, and the double equal sign “=” is a comparison operator. What is the = operator used for? The “is equal to” operator is a comparison operator used to compare 2 objects for equality. How to read “=” ? The “=” symbol is called “ is equal to” or “ equal to” for short and is used in many programming languages like C, C++, Python, etc. The objects under comparison can be strings or integers or some special user-defined class What is = in python? ‘=’ is an operator which is used to compare the equality of 2 objects in Python. Table#1: Python’s “=” operator Cheatsheet “=” is for comparison while “=” is for equality To check if 2 objects are equal in terms of value The phrase “Practice Makes Perfect” did not survive so many centuries for no reason!įor those of you who came here just to refresh your memories, here is a cheatsheet! Python’s “=” Operator CheatSheet What is “=” in Python? So put on your coding hats, open your laptops and start experimenting and playing with the code shown in the examples as you read them! The best trick to make our brains remember stuff is via active learning. Python is no exception to this rule!Įven though the concepts might look simple, our brains are really good at understanding the concepts but not so good at remembering them! The first step in the journey towards mastery of any programming language is to learn about the various operators provided by that language and learn how to wield them. …or I could change programming languages comparison of the notation of the not equals operator to create the illusion of JavaScript being the outlier here.In this article let us learn about the “=” (double equal) operator in python and learn what it means and how to make use of this operator the same way the pros do! Literally every other programming language (FORTRAN, Haskell, Lisp, ALGOL, Pascal, Ada, Eiffel) uses /= for the “not equal to” operator. I’m not asking to remove ~=, it’d just change /= to ~= in the backend so we have the option to use either. It would be nice if Roblox’s Luau had syntax sugar to allow us to write /= instead of ~=. I could rephrase this section of argument to argue that /= could also be a syntax sugar to ~=: Should the not equal operator also be allowed to be written as /= and ? Perhaps you only selected programming languages with the not equal operator being != as an example (confirmation bias(?))? Just because these programming languages uses the != notation (perhaps it was derived from C even if these programming languages don’t use braces for control blocks) for not equals operation does not mean all other programming languages uses !=.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |