Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8022809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:22:44+00:00 2026-06-04T22:22:44+00:00

I’m learning basic Boolean logic with Python. I understand the equality operators but get

  • 0

I’m learning basic Boolean logic with Python. I understand the equality operators but get confused when ands and ors get thrown in. Take a look at the following code for example:

people = 20
cats = 30
dogs = 15

if people < cats:
   print "too many cats! the world is doomed!"

if people == cats or dogs == cats:
   print "this is too hard"

I understand the first if statement and why it prints. i don’t know how the second if statement is evaluated. How could I change it to get that line to print?

Thanks for your help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T22:22:45+00:00Added an answer on June 4, 2026 at 10:22 pm

    and requires that all of its parts in the expression evaluate to True for the whole expression to be True.

    or is much less picky, as soon as any part of the expression evaluates to True the whole expression is True.

    You may come across the term short-circuiting in this context. It simply means that we stop evaluating expressions as soon as we can determine its outcome.

    So for an and we can stop looking at the rest of the expression as soon as we find a part that evaluates to False because at that point the expression can never evaluate to True.

    Likewise, with or, as soon as we find a part that’s True, we know the whole expression will be True and there won’t be a reason to look further.

    For the code example you posted:

    if people == cats or dogs == cats:
        print "this is too hard"
    

    if either one of these, or both of people == cats, dogs == cats evaluated to True, the whole expression in the if statement would become True. Since neither of them are True, the expression in the if statement fails, i.e., is False, and the print statement is not executed.

    Finally, if you wanted to print statement to execute, you’d have to ensure that the Boolean expression evaluated to True. One way would be to change to value of
    dogs to 30 because then dogs == cats would be True and that would be
    sufficient to make the whole expression True and get the print to execute.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want to construct a data frame in an Rcpp function, but when I
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.