Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 14th, 2008, 11:06 PM   #1
Dunganb
Newbie
 
Join Date: Jun 2008
Location: Pennsylvania
Posts: 5
Rep Power: 0 Dunganb is on a distinguished road
Question Short circuiting...

Hey everyone,

I was reading through a tutorial for Python on wikibooks and got hung up at a spot about short circuiting. I was wondering if you could help me through the logic the program is using to return the results. Here is the input/output:

python Syntax (Toggle Plain Text)
  1. >>> 'a' == ('a' or 'b')
  2. True
  3. >>> 'b' == ('a' or 'b')
  4. False
  5. >>> 'a' == ('a' and 'b')
  6. False
  7. >>> 'b' == ('a' and 'b')
  8. True

The second and fourth ones are the ones I am having trouble understanding. From what I read on wikibooks, it has something to do with the first and second strings being non-empty strings, but I couldn't really see how writing the previous example is different from the following:

python Syntax (Toggle Plain Text)
  1. >>> 'a' == 'a' or 'a' == 'b'
  2. True
  3. >>> 'b' == 'a' or 'b' == 'b'
  4. True
  5. >>> 'a' == 'a' and 'a' == 'b'
  6. False
  7. >>> 'b' == 'a' and 'b' == 'b'
  8. False

Am I just missing something here?
Dunganb is offline   Reply With Quote
Old Jun 15th, 2008, 3:27 PM   #2
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 855
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Re: Short circuiting...

Perhaps this will help.
titaniumdecoy is offline   Reply With Quote
Old Jun 15th, 2008, 5:32 PM   #3
Dunganb
Newbie
 
Join Date: Jun 2008
Location: Pennsylvania
Posts: 5
Rep Power: 0 Dunganb is on a distinguished road
Re: Short circuiting...

Thanks titaniumdecoy, that article answered a lot of the areas where I was confused.
Dunganb is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Short Hand Decimal To Binary Vice Versa Good or Bad? CIRCLE C 2 Sep 23rd, 2007 7:57 PM
Help debug (short program) sixstringartist C 17 Sep 11th, 2006 11:58 PM
Displaying a Short description billpull PHP 7 Jul 16th, 2006 10:34 AM
how short can you make this angry_asian C++ 19 Jun 29th, 2006 6:27 PM
Short Challenge skuinders Coder's Corner Lounge 25 Aug 16th, 2005 9:03 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:45 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC