[Python] How to create set with values 1, 0, True, False along with other values in the same...

Discussão em 'Python' iniciado por Stack, Março 17, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to create a set having different values along with True, False, 1, 0.

    I am aware that Python treats 1 as True and 0 as False. Imperatively, since the set keeps only the unique values, my set stores either of 1 or True, and of 0 or False.

    Is there any workaround to deal with the above requirement?

    set1 = {"Python", "Java", 1, 0, 23.45, True, False}


    Output1: {"Python", "Java", 1, 0, 23.45} (not in the same order obviously)

    Output2: {"Python", "Java", 1, False, 23.45} (not in the same order obviously)

    Continue reading...

Compartilhe esta Página