this post was submitted on 31 Oct 2024
48 points (96.2% liked)

Python

6375 readers
6 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

๐Ÿ“… Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

๐Ÿ Python project:
๐Ÿ’“ Python Community:
โœจ Python Ecosystem:
๐ŸŒŒ Fediverse
Communities
Projects
Feeds

founded 1 year ago
MODERATORS
 

Note: The attached image is a screenshot of page 31 of Dr. Charles Severance's book, Python for Everybody: Exploring Data Using Python 3 (2024-01-01 Revision).


I thought = was a mathematical operator, not a logical operator; why does Python use

>= instead of >==, or <= instead of <==, or != instead of !==?

Thanks in advance for any clarification. I would have posted this in the help forums of FreeCodeCamp, but I wasn't sure if this question was too.......unspecified(?) for that domain.

Cheers!

ย 


Edit: I think I get it now! Thanks so much to everyone for helping, and @FizzyOrange@programming.dev and @itslilith@lemmy.blahaj.zone in particular! ^_^

you are viewing a single comment's thread
view the rest of the comments
[โ€“] FizzyOrange@programming.dev 22 points 2 weeks ago (14 children)

>= and <= match the mathematical operators. The question you want to ask is why doesn't it use = for equality, and the answer is that = is already used for assignment (inherited from C among other languages).

In theory a language could use = for assignment and equality but it might be a bit confusing and error prone. Maybe not though. Someone try it and report back.

[โ€“] EveryMuffinIsNowEncrypted@lemmy.blahaj.zone 1 points 2 weeks ago* (last edited 2 weeks ago) (9 children)

I think what I'm most confused about is I cannot for the life of me seem to wrap my head around the difference between "assignment" and "equality". They seem exactly the same to me: when a variable is assigned a value, it's equal to that value now.

Even if I were write the program

x = 20
print(x*2)

it would still print 40. Because x is equal to 20. Because it was assigned the value of 20.

Hell, I've even heard Dr. Severance say "equal to" in this context in earlier videos multiple times.

[โ€“] GetOffMyLan@programming.dev 2 points 2 weeks ago* (last edited 2 weeks ago)

How would you check two variables have equal values without changing the value of one otherwise?

Assignment you are assigning a value to the left side. Equality you are checking if the left and right are equal.

It's "set equal to" Vs "is equal to" one is an operation the other is a condition.

load more comments (8 replies)
load more comments (12 replies)