How to know if a list has an even or odd number of elements

后端 未结 8 1926
离开以前
离开以前 2021-01-28 01:20

How can I find out if there is even, or odd, number of elements in an arbitrary list.

I tried list.index() to get all of the indices... but I still don\'t k

8条回答
  •  [愿得一人]
    2021-01-28 01:58

    your_list = [1,2,3,(4,5)]
    
    # modulo operation finds the remainder of division of one number by another.
    if len(your_list) % 2 == 0:
        print "Even Number"
    else:
        print"number is odd"
    

提交回复
热议问题