Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

367
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda