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

  • SEARCH
  • Home
  • 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 7736169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:40:44+00:00 2026-06-01T07:40:44+00:00

if aa or bb or cc or dd or ee or ff in attrs[show]:

  • 0
if "aa" or "bb" or "cc" or "dd" or "ee" or "ff" in attrs["show"]:
    self.xx = xxxx

I have a code like this, to check if attrs[“show”] contains either of these strings, then assign some value to self.xx

But is this “IF” command is correct? Because from my results, it seems like this if command is always true(which is impossible)

  • 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-01T07:40:45+00:00Added an answer on June 1, 2026 at 7:40 am

    Try the following:

    if any(s in attrs["show"] for s in ("aa", "bb", "cc", "dd", "ee", "ff")):
        self.xx = xxxx
    

    Your current if statement will always evaluate to True, because instead of checking if each string is in attrs["show"] you are checking if "aa" is True, or if "bb" is True, and on and on. Since "aa" will always evaluate as True in a Boolean context, you will always enter the if clause.

    Instead, use the any() function as in my example, which accepts an iterable and returns True if any of its elements are True. Similar to a bunch of or‘s as in your code, this will short-circuit as soon as it finds an element that is True. In this example, the above code is equivalent to the following (but much more concise!):

    if ("aa" in attrs["show"] or "bb" in attrs["show"] or "cc" in attrs["show"] or
        "dd" in attrs["show"] or "ee" in attrs["show"] or "ff" in attrs["show"]):
        self.xx = xxxx
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this strange error, When I call $element_attrs = $element -> attributes(); I
Relevant Code Snippet: public class MyPreference extends Preference { public MyPreference(Context context, AttributeSet attrs)
this is my form: class IPTrackerSearchForm(forms.Form): keyword = forms.CharField(max_length=100, widget=forms.TextInput(attrs={'size':'50'})) search_in = forms.ChoiceField(required=False, choices=ANY_CHOICE
Ok, so I have this jquery function to that grabs the checkbox's value and
I have li.box , li.car which are inside a $(this) which contain modified values
Hy , I have the following code for mai tabs ... $(document).ready(function() { $(#continut_right
I have those code: public class ContentEditText extends EditText { /* * Constructors */
this will show up in the sidebar, that is why i put it in
$.get($(this).attr('id'), function(data){ var qp_post = $(data).filter('title'); alert(qp_post); }); This fetches the content fine however
$.post($(this).attr(action), $(this).serialize(), function(json) { alert('red'); AddItemAjax(json); }, json); This works in Chrome but not

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.