Can't understand why the code shows incorrect output. The output should be 1 and yes but instead of yes it shows NoConvert bytes to a string?Filters in Python3Why Is the Output of My Range Function Not a List?zip function giving incorrect outputWhy does list in program give an unexpected output?Python zip function - weird resultWhy is output not printing a list?python code running else statement even after if statement is trueWhy is the else statement in this code not working?Concatenate arrays in Python - output error

Can I enter the UK without my husband if we said we'd travel together in our visa application?

Is it acceptable to say that a reviewer's concern is not going to be addressed because then the paper would be too long?

Convex hull in a discrete space

What does Sartre mean by "pédéraste" - pederast or homosexual?

Difference between "rip up" and "rip down"

Number of list elements less than a given integer

Why was it decided in 1956 to abolish the spelling чорт (devil) in favor of чёрт?

I reverse the source code, you reverse the input!

What does מעלה עליו הכתוב mean?

How to check if my quadrature encoder is broken or not?

Is the order of words purely based on convention?

Why, even after his imprisonment, people keep calling Hannibal Lecter "Doctor"?

What exactly did this mechanic sabotage on the American Airlines 737, and how dangerous was it?

New road bike: alloy dual pivot brakes work poorly

Why are there two fundamental laws of logic?

Flowers sent by the birds

Align all symbols in a LaTeX equation

Why is STARTTLS still used?

Designing a time thief proof safe

Help in drawing resonance structures in case of polybasic acids

Why is a road bike faster than a city bike with the same effort? How much faster it can be?

Comma Code - Automate the Boring Stuff with Python

Seventh degree polynomial

Is a Middle Name a Given Name?



Can't understand why the code shows incorrect output. The output should be 1 and yes but instead of yes it shows No


Convert bytes to a string?Filters in Python3Why Is the Output of My Range Function Not a List?zip function giving incorrect outputWhy does list in program give an unexpected output?Python zip function - weird resultWhy is output not printing a list?python code running else statement even after if statement is trueWhy is the else statement in this code not working?Concatenate arrays in Python - output error






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















Iam learning python and wanted to test the concept of list and if/else function.



num1 = ["1"]
c = num1[0]
print(c)
if num1[0] == 1:
print("yes")
else:
print("no")


I expect the output to be 1 yes
but I get the output as 1 no
why does it not enter if block even when the condition is met










share|improve this question
































    0















    Iam learning python and wanted to test the concept of list and if/else function.



    num1 = ["1"]
    c = num1[0]
    print(c)
    if num1[0] == 1:
    print("yes")
    else:
    print("no")


    I expect the output to be 1 yes
    but I get the output as 1 no
    why does it not enter if block even when the condition is met










    share|improve this question




























      0












      0








      0








      Iam learning python and wanted to test the concept of list and if/else function.



      num1 = ["1"]
      c = num1[0]
      print(c)
      if num1[0] == 1:
      print("yes")
      else:
      print("no")


      I expect the output to be 1 yes
      but I get the output as 1 no
      why does it not enter if block even when the condition is met










      share|improve this question
















      Iam learning python and wanted to test the concept of list and if/else function.



      num1 = ["1"]
      c = num1[0]
      print(c)
      if num1[0] == 1:
      print("yes")
      else:
      print("no")


      I expect the output to be 1 yes
      but I get the output as 1 no
      why does it not enter if block even when the condition is met







      python-3.x






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 28 at 19:18









      Paandittya

      6395 silver badges16 bronze badges




      6395 silver badges16 bronze badges










      asked Mar 28 at 18:41









      Prnv_atPrnv_at

      1




      1

























          1 Answer
          1






          active

          oldest

          votes


















          3
















          Arent you comparing string with integer? try if (num[0]=="1")






          share|improve this answer



























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );














            draft saved

            draft discarded
















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55404763%2fcant-understand-why-the-code-shows-incorrect-output-the-output-should-be-1-and%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            3
















            Arent you comparing string with integer? try if (num[0]=="1")






            share|improve this answer





























              3
















              Arent you comparing string with integer? try if (num[0]=="1")






              share|improve this answer



























                3














                3










                3









                Arent you comparing string with integer? try if (num[0]=="1")






                share|improve this answer













                Arent you comparing string with integer? try if (num[0]=="1")







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 28 at 18:44









                MurksiukeMurksiuke

                315 bronze badges




                315 bronze badges

































                    draft saved

                    draft discarded















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55404763%2fcant-understand-why-the-code-shows-incorrect-output-the-output-should-be-1-and%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                    Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript