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 8979543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:52:17+00:00 2026-06-15T19:52:17+00:00

My code is: varA = 5 varB = ‘dog’ if type(varB) == ‘string’: print(string

  • 0

My code is:

varA = 5
varB = 'dog'
if type(varB) == 'string':
    print("string involved")
elif type(varA) == 'string':
    print("string involved")
else:
    if varA > varB:
        print("bigger")
    elif varA == varB:
        print("equal")
    elif varA < varB:
        print("smaller")

I get error on line 8. I want the code not to react on line 7 else statement, if it has already met the requirements for if(line3) or elif(line5)!

Also, how to use ‘or’ method so it joins toget if(line3) and elif(line5) statements?

  • 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-15T19:52:19+00:00Added an answer on June 15, 2026 at 7:52 pm

    Try using isinstance to check for type:

    varA = 5
    varB = 'dog'
    if isinstance(varA, str) or isinstance(varB, str):
        print("string involved")
    else:
        if varA > varB:
            print("bigger")
        elif varA == varB:
            print("equal")
        else:
            print("smaller")
    

    Here you are checking that the variables are of the str type, and if either one of them is, you know a string is involved and will therefore not execute the else code.

    The or can be done by essentially combining the two conditions into one line, as in the example. Here it isn’t a big issue, another way you can simulate an or statement is to use any, which checks if any of the conditions are True and executes if so:

    if any((isinstance(varA, str), isinstance(varB, str))):
        # Code...
    

    This comes in handy when you have a large data structure and need to do a similar or comparison. The and equivalent is all, which has the same syntax, just using all instead of any:

    if all((isinstance(varA, str), isinstance(varB, str))):
        # This code will evaluate if all values are strings
    

    And if you have a bunch of checks and get tired of typing isinstance, you can bundle that part a bit further by using a generator in combination with any or all:

    if any(isinstance(x, str) for x in (varA, varB)):
        # Code
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Code: String message = MessageFormat.format(error {0},e); E.g. message: java.text.ParseException: Unparseable date: sdf sf sa
I have code : function compute() { if ($('input[name=type]:checked').val() != undefined) { var a
Look at this code: var a:Number = 1; var b:String = hello; if (a
I have the following code: public static string FormatHostAndUrl(this HttpSessionStateBase session) { var a
Look at the following code: class A { public string DoSomething(string str) { return
if i don't specifically type a variable in my code will it compile as
I am trying to multiply to number type variables: The code is something like
I have this code: var a:Array = [ Ramsey, Tusey, Iuser,Sephora,'user', 'reseo', 'nesey', 'sela']
I have this code: var fullpath = $(this)[0].src; var a = document.createElement('a'); a.href =
Given the following code: var a = 'somegarbage=http://somesite.com/foo/bar/&moregarbage'; var result = a.match(/http.+\//g); Produces the

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.