473,698 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Newcomer struggling with tutorial

Just joined this group, fascinated by Python. Many thanks to those who have
worked so hard on it!

One big problem, though: I was completely thrown by this, which I quote
from the Tutorial:
Comparisons can be chained. For example, a < b == c tests whether a is

less than b and moreover b equals c.

I threw a mental wobbly and wasted two hours over this:

a = -1
b = 77
c = 1

(a < b)
True

True == c
True

(a < b) == c
False

Unfortunately I was brought up with the belief that if A == B and B == C,
then A should == C.

I confess that after two hours worrying about this I have given up on
Python and uninstalled it. A shame: it looked so good!

CPKS
Jul 18 '05 #1
6 1409
CPK Smithies wrote:

I threw a mental wobbly and wasted two hours over this:

a = -1
b = 77
c = 1

(a < b)
True

True == c
True

(a < b) == c
False

Unfortunately I was brought up with the belief that if A == B and B == C,
then A should == C.
Strangely enough it does. Your last line is incorrect. Try executing
it again, from scratch, without reassigning any of the three values
you originally entered, because that's surely what you have done to
get that result.

Using Python 2.3:

C:\>python
Python 2.3.1 (#47, Sep 23 2003, 23:47:32) [MSC v.1200 32 bit (Intel)] on win32
Type "help", "copyright" , "credits" or "license" for more information.
a = -1
b = 77
c = 1
a < b True True True True == c True (a < b) == c

True
I confess that after two hours worrying about this I have given up on
Python and uninstalled it. A shame: it looked so good!


A shame indeed, were it in fact how Python worked.

-Peter
Jul 18 '05 #2
On Sun, Oct 05, 2003 at 03:17:31AM +0000, CPK Smithies wrote:
Just joined this group, fascinated by Python. Many thanks to those who have
worked so hard on it!

One big problem, though: I was completely thrown by this, which I quote
from the Tutorial:
Comparisons can be chained. For example, a < b == c tests whether a is less than b and moreover b equals c.

I threw a mental wobbly and wasted two hours over this:

a = -1
b = 77
c = 1

(a < b)
True

True == c
True

(a < b) == c
False


Did you type this from memory, rather than copying and pasting? This is
what I see:
a = -1
b = 77
c = 1
(a < b) True True == c True (a < b) == c True a < b == c False (a < b) and (b == c)

False
Do you see the distinction? "a < b == c" is the same as writing "(a < b)
and (b == c)" in python, but "(a < b) == c" isn't. Perhaps the tutorial's
wording is unclear.
I confess that after two hours worrying about this I have given up on
Python and uninstalled it. A shame: it looked so good!


Then why are you posting here? ;)

-Andrew.
Jul 18 '05 #3
> a = -1
b = 77
c = 1

(a < b)
True

True == c
True

(a < b) == c
False

Unfortunately I was brought up with the belief that if A == B and B == C,
then A should == C.

I confess that after two hours worrying about this I have given up on
Python and uninstalled it. A shame: it looked so good!


well isnt that the defeatist way to go.

sounds like you're trying to compare two values that are not necessarily
the same. You're thinking in boolean logic, and trying to express it in
a totally different way.

You wanted :

a = 1
b = 2
c = 1
print ((a<2) & c)

So we are saying we want to have BOTH (a<2) AND (c) to be true.

Dave

Jul 18 '05 #4
CPK Smithies wrote:
Just joined this group, fascinated by Python. Many thanks to those who have
worked so hard on it!

One big problem, though: I was completely thrown by this, which I quote
from the Tutorial:

Comparisons can be chained. For example, a < b == c tests whether a is


less than b and moreover b equals c.

I threw a mental wobbly and wasted two hours over this:

a = -1
b = 77
c = 1

(a < b)
True

True == c
True

(a < b) == c
False

Unfortunately I was brought up with the belief that if A == B and B == C,
then A should == C.

I confess that after two hours worrying about this I have given up on
Python and uninstalled it. A shame: it looked so good!

CPKS

I have not read the tutorial, but the section you quote is quite clear
about what chaining means. I did not know about this, but it is kind of
neat. For example:
a = 1; b = 2; c = 3; d = 4
a < b < c < d < 5 True a < b < c < d < 3

False

Python actually conforms more to standard math notation for transitivity
than whatever language you were 'brought up' on, which results in
confusion when you are used to standard algebraic notation. I still
recall 39 years ago being quite puzzled when I saw the statement:
LET A = A+1

Good luck with whatever language you choose. Personally, I have found
Python to be a wonderful practical tool for the occasional programmer
like me. And this group is a nice community for the isolated user
because someone usually supplies answers quickly and non-judgementally
(for the most part).

david

Jul 18 '05 #5

"CPK Smithies" <cp**@NOSPAM.bt openworld.com> wrote in message
news:bl******** **@hercules.bti nternet.com...
from the Tutorial:
Comparisons can be chained. For example, a < b == c tests whether a is
less than b and moreover b equals c.

This means that a < b == c is equivalent to
(a < b) and (b == c) and not
(a < b) == c., which is something else.

Chained operators are *not* 'associative' -- you cannot insert parens
unless you so for each overlapping pair of args and insert 'and'
between each.
I threw a mental wobbly and wasted two hours over this:

a = -1
b = 77
c = 1

(a < b)
True

True == c
True
For a < b == c, the second test Python makes is b==c (False).
But this matches for your next test.
(a < b) == c
False
For 2.2.1 (which does not have True/False on Windows .
a,b,c = -1, 77, 1
a < b 1 (a < b) == 1

1

What version/machine were you running? Please cut and paste actual
output. If you have really discovered a bug in current Python, we
would want to know and fix it.
Unfortunately I was brought up with the belief that if A == B and B == C, then A should == C.
Why 'unfortunately' ? For builtin objects, this is true in Python.
I confess that after two hours worrying about this I have given up on Python and uninstalled it. A shame: it looked so good!


If you really did that, it was a real shame.

Terry J. Reedy
Jul 18 '05 #6
Like others have pointed out, Python does that chained comparison right.

I confess that after two hours worrying about this I have given up on
Python and uninstalled it. A shame: it looked so good!

CPKS


That seems to be a flame bait to me. ;)
Perhaps not a good one because people didn't bite. Or we are just too
Pythonic (and squeeze instead) :-)

Cheers,
Pm


Jul 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
1238
by: Florian Daniel Otel | last post by:
Hello all, As the subject says, I am a newcomer to Python and I have a newcomer question wrt namespaces and variable scope. Obviously, I might be missing smth obvious, so TIA for the patience and/or pointers to relevant resources My problem: I just discovered (by mistake) that attempting to assign a value to a non-local dictionary/list member does NOT generate an " UnboundLocalError" exception and the assignment is preserved upon
160
4666
by: RG | last post by:
Greetings friends, This semester I have started a course in C programming. I was moving along fine until I reached to the topic of loops (feeling embarrassed among you elite programmers). My prof. would post program questions and the solutions online. For practice I would try to do the problems. I would reach to a certain point in the code, for example as far as error trapping, but when the loop arrives, like knowing whether to use...
5
1401
keyvanrahmadi
by: keyvanrahmadi | last post by:
Hopefully I am posting in the right section and not annoying everyone, if I am then please except my sincere apology for wasting your time and hopefully the Mods will move it to the right location and forgive me. I have just recently finished learning Mysql databases and since I seriously enjoyed studying it, I have taken on myself to learn other databases such as Access and Oracel. As you all are well aware of its nearly impossible for a...
0
8601
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9156
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9021
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8892
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4365
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3043
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2327
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1998
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.