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?
Santiago Trujillo
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
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.
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