Different ValueError for the same operation in List and TupleHow do I check if a list is empty?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonWhat is the difference between Python's list methods append and extend?Does Python have a ternary conditional operator?What's the difference between lists and tuples?How to make a flat list out of list of listsHow do I concatenate two lists in Python?How to clone or copy a list?How do I list all files of a directory?

How to avoid unconsciously copying the style of my favorite writer?

Is there anything wrong with Thrawn?

3D Statue Park: U shapes

How much were the LMs maneuvered to their landing points?

Word for showing a small part of something briefly to hint to its existence or beauty without fully uncovering it

Did the IBM PC use the 8088's NMI line?

Is dd if=/dev/urandom of=/dev/mem safe?

Problem in styling a monochrome plot

Is it normal practice to screen share with a client?

AC contactor 1 pole or 2?

Keeping an "hot eyeball planet" wet

Why did Saturn V not head straight to the moon?

Why are so many countries still in the Commonwealth?

Examples of simultaneous independent breakthroughs

Why can't my huge trees be chopped down?

When going by a train from Paris to Düsseldorf (Thalys), can I hop off in Köln and then hop on again?

Trapped in an ocean Temple in Minecraft?

Writing a clean implementation of Rock, Paper, Scissors game in c++

401(k) investment after being fired. Do I own it?

Why/when is AC-DC-AC conversion superior to direct AC-Ac conversion?

Anybody know what this small Nintendo stand is for?

What's the difference between 2a and 10a charging options?

Is it legal for private citizens to "impound" e-scooters?

Weed in Massachusetts: underground roots, skunky smell when bruised



Different ValueError for the same operation in List and Tuple


How do I check if a list is empty?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonWhat is the difference between Python's list methods append and extend?Does Python have a ternary conditional operator?What's the difference between lists and tuples?How to make a flat list out of list of listsHow do I concatenate two lists in Python?How to clone or copy a list?How do I list all files of a directory?






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








2















I am curious why ValueErrors are different in List and Tuple when I try to get an index. ValueError of a list returns in well format with actual argument "ValueError: 'ITEM' is not in list", whereas tuple returns something like this "ValueError: tuple.index(x): x not in tuple".
I think List and Tuple both are calling same index() method then why it is raising different ValueErrors?




>>> jframe_li
['Angular', 'React', 'Vue.js', 'Ember.js', 'Mereor', 'Node.js', 'Backbone.js']
>>> jframe_tu
('Angular', 'React', 'Vue.js', 'Ember.js', 'Mereor', 'Node.js', 'Backbone.js')
>>> jframe_li.index('React')
1
>>> jframe_tu.index('React')
1
>>> jframe_li.index('react')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: 'react' is not in list

>>> jframe_tu.index('react')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: tuple.index(x): x not in tuple









share|improve this question
























  • "I think List and Tuple both are calling same index() method" - I'm not sure this is a valid assumption.

    – snakecharmerb
    Mar 26 at 17:34











  • @snakecharmerb According to docs, Tuples implement all of the common sequence operations which include .index, now would you say it implements it in a different way?

    – Samuel
    Mar 26 at 17:43












  • @Samuel as the answer below demonstrates, I would say that they are implemented differently.

    – snakecharmerb
    Mar 26 at 19:59











  • Yeah, you were right, I also learned in the process.

    – Samuel
    Mar 26 at 20:00


















2















I am curious why ValueErrors are different in List and Tuple when I try to get an index. ValueError of a list returns in well format with actual argument "ValueError: 'ITEM' is not in list", whereas tuple returns something like this "ValueError: tuple.index(x): x not in tuple".
I think List and Tuple both are calling same index() method then why it is raising different ValueErrors?




>>> jframe_li
['Angular', 'React', 'Vue.js', 'Ember.js', 'Mereor', 'Node.js', 'Backbone.js']
>>> jframe_tu
('Angular', 'React', 'Vue.js', 'Ember.js', 'Mereor', 'Node.js', 'Backbone.js')
>>> jframe_li.index('React')
1
>>> jframe_tu.index('React')
1
>>> jframe_li.index('react')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: 'react' is not in list

>>> jframe_tu.index('react')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: tuple.index(x): x not in tuple









share|improve this question
























  • "I think List and Tuple both are calling same index() method" - I'm not sure this is a valid assumption.

    – snakecharmerb
    Mar 26 at 17:34











  • @snakecharmerb According to docs, Tuples implement all of the common sequence operations which include .index, now would you say it implements it in a different way?

    – Samuel
    Mar 26 at 17:43












  • @Samuel as the answer below demonstrates, I would say that they are implemented differently.

    – snakecharmerb
    Mar 26 at 19:59











  • Yeah, you were right, I also learned in the process.

    – Samuel
    Mar 26 at 20:00














2












2








2








I am curious why ValueErrors are different in List and Tuple when I try to get an index. ValueError of a list returns in well format with actual argument "ValueError: 'ITEM' is not in list", whereas tuple returns something like this "ValueError: tuple.index(x): x not in tuple".
I think List and Tuple both are calling same index() method then why it is raising different ValueErrors?




>>> jframe_li
['Angular', 'React', 'Vue.js', 'Ember.js', 'Mereor', 'Node.js', 'Backbone.js']
>>> jframe_tu
('Angular', 'React', 'Vue.js', 'Ember.js', 'Mereor', 'Node.js', 'Backbone.js')
>>> jframe_li.index('React')
1
>>> jframe_tu.index('React')
1
>>> jframe_li.index('react')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: 'react' is not in list

>>> jframe_tu.index('react')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: tuple.index(x): x not in tuple









share|improve this question
















I am curious why ValueErrors are different in List and Tuple when I try to get an index. ValueError of a list returns in well format with actual argument "ValueError: 'ITEM' is not in list", whereas tuple returns something like this "ValueError: tuple.index(x): x not in tuple".
I think List and Tuple both are calling same index() method then why it is raising different ValueErrors?




>>> jframe_li
['Angular', 'React', 'Vue.js', 'Ember.js', 'Mereor', 'Node.js', 'Backbone.js']
>>> jframe_tu
('Angular', 'React', 'Vue.js', 'Ember.js', 'Mereor', 'Node.js', 'Backbone.js')
>>> jframe_li.index('React')
1
>>> jframe_tu.index('React')
1
>>> jframe_li.index('react')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: 'react' is not in list

>>> jframe_tu.index('react')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: tuple.index(x): x not in tuple






python python-3.x list tuples






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 26 at 17:18









Aran-Fey

20.3k5 gold badges43 silver badges82 bronze badges




20.3k5 gold badges43 silver badges82 bronze badges










asked Mar 26 at 17:18









Hardik PatelHardik Patel

336 bronze badges




336 bronze badges












  • "I think List and Tuple both are calling same index() method" - I'm not sure this is a valid assumption.

    – snakecharmerb
    Mar 26 at 17:34











  • @snakecharmerb According to docs, Tuples implement all of the common sequence operations which include .index, now would you say it implements it in a different way?

    – Samuel
    Mar 26 at 17:43












  • @Samuel as the answer below demonstrates, I would say that they are implemented differently.

    – snakecharmerb
    Mar 26 at 19:59











  • Yeah, you were right, I also learned in the process.

    – Samuel
    Mar 26 at 20:00


















  • "I think List and Tuple both are calling same index() method" - I'm not sure this is a valid assumption.

    – snakecharmerb
    Mar 26 at 17:34











  • @snakecharmerb According to docs, Tuples implement all of the common sequence operations which include .index, now would you say it implements it in a different way?

    – Samuel
    Mar 26 at 17:43












  • @Samuel as the answer below demonstrates, I would say that they are implemented differently.

    – snakecharmerb
    Mar 26 at 19:59











  • Yeah, you were right, I also learned in the process.

    – Samuel
    Mar 26 at 20:00

















"I think List and Tuple both are calling same index() method" - I'm not sure this is a valid assumption.

– snakecharmerb
Mar 26 at 17:34





"I think List and Tuple both are calling same index() method" - I'm not sure this is a valid assumption.

– snakecharmerb
Mar 26 at 17:34













@snakecharmerb According to docs, Tuples implement all of the common sequence operations which include .index, now would you say it implements it in a different way?

– Samuel
Mar 26 at 17:43






@snakecharmerb According to docs, Tuples implement all of the common sequence operations which include .index, now would you say it implements it in a different way?

– Samuel
Mar 26 at 17:43














@Samuel as the answer below demonstrates, I would say that they are implemented differently.

– snakecharmerb
Mar 26 at 19:59





@Samuel as the answer below demonstrates, I would say that they are implemented differently.

– snakecharmerb
Mar 26 at 19:59













Yeah, you were right, I also learned in the process.

– Samuel
Mar 26 at 20:00






Yeah, you were right, I also learned in the process.

– Samuel
Mar 26 at 20:00













1 Answer
1






active

oldest

votes


















4














There are implementation differences in the index methods for lists and tuples, including in the text of a raised ValueError.



See ValueError string for tuple.index and ValueError string for list.index






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/3.0/"u003ecc by-sa 3.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%2f55362835%2fdifferent-valueerror-for-the-same-operation-in-list-and-tuple%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









    4














    There are implementation differences in the index methods for lists and tuples, including in the text of a raised ValueError.



    See ValueError string for tuple.index and ValueError string for list.index






    share|improve this answer



























      4














      There are implementation differences in the index methods for lists and tuples, including in the text of a raised ValueError.



      See ValueError string for tuple.index and ValueError string for list.index






      share|improve this answer

























        4












        4








        4







        There are implementation differences in the index methods for lists and tuples, including in the text of a raised ValueError.



        See ValueError string for tuple.index and ValueError string for list.index






        share|improve this answer













        There are implementation differences in the index methods for lists and tuples, including in the text of a raised ValueError.



        See ValueError string for tuple.index and ValueError string for list.index







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 26 at 18:50









        benvcbenvc

        8,3041 gold badge13 silver badges30 bronze badges




        8,3041 gold badge13 silver badges30 bronze badges


















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            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%2f55362835%2fdifferent-valueerror-for-the-same-operation-in-list-and-tuple%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

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현