Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

366
Vistas
How to declare multiple variables with type annotation syntax in Python?

As far as I know, now we can declare variables using type annotation syntax in Python 3.6 as following code.

def printInt():
    a: int = 0
    b: int = 1
    c: int = 2
    print(a, b, c)

What I want to do is declaring variables a, b, c in one line.

I tried a, b, c: int, but it returns error.

Also a: int=0, b: int=1, c: int=2 returns error too.

Is there any way to declare multiple variables using type annotation syntax in one line?

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

If you really want to use annotation then you can do this in this form:-

a: int;b: int;c: int
a,b,c = range(3)
print(a,b,c) #As output 0 1 2
over 4 years ago · Santiago Trujillo Denunciar

0

 a: int = 0; b: int = 1; c: int = 2

would actually work. If you are looking for a way to avoid repeating int all times, I am afraid you cannot as of Python 3.7.

over 4 years ago · Santiago Trujillo Denunciar

0

Python is completely object oriented, and not "statically typed". You do not need to declare variables before using them, or declare their type. Every variable in Python is an object.

a,b,c=0,1,2

Or the following maybe what you are looking for

def magic(a: str, b: str) -> int:
    light = a.find(b)
    return light
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda