[Python] Is it possible to convert type to int in Python

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

  1. Stack

    Stack Membro Participativo

    I am a beginner in using python or any other programming language to be precise. In order to deepen my knowledge of python I decided to work on some projects. I encountered an issue while working on one recently. I intend to turn type to int but every time I do that, python throws the error:


    TypeError: int() argument must be a string, a bytes-like object or a real number, not 'type'
    ​

    So I decided to convert it to a string, then later convert it to int using the built-in function int(str() Then again an error message outputs:


    ValueError: invalid literal for int() with base 10: "<class 'slice'>"
    ​

    Can I convert type to int

    This is the code i am working on

    if int(str(slice)) == (len(x)):

    Continue reading...

Compartilhe esta Página