Expected type str
, Tuple[str]
was returned in python3.8
CA2 = "2CA",
CA3 = "3CA",
CA4 = "4CA",
LTE = "LTE"
def temp() -> str:
ca_list = [1, 2, 3]
if len(ca_list) == 1:
result = LTE
elif len(ca_list) == 2:
result = CA4
elif len(ca_list) == 3:
result = CA2
else:
result = CA3
return result
temp()
output: ('2CA',)
CodePudding user response:
The comma after each automatically converts the string such as "2CA"
to a tuple like ('2CA',)
so therefore your output is a tuple containing it.
if you want a string output just remove the commas
see here: Why does adding a trailing comma after a variable name make it a tuple?
CodePudding user response:
Expect for LTE
all are tuples i.e CA2, CA3, CA4. In python ()
doesn't make it a tuple but ,
(comma) does.
a = (1) # a is 1 not tuple of size 1
b = 1, # or (1, ) now b is tuple of size 1.
c = 1, 2, 3 # c is (1, 2, 3)