2019-05-03 09:18:30 -04:00
|
|
|
# test various type conversions
|
|
|
|
|
|
|
|
import micropython
|
|
|
|
|
2023-02-01 19:51:48 -05:00
|
|
|
|
2019-05-03 09:18:30 -04:00
|
|
|
# converting incoming arg to bool
|
|
|
|
@micropython.viper
|
|
|
|
def f1(x: bool):
|
|
|
|
print(x)
|
2020-03-22 22:26:08 -04:00
|
|
|
|
|
|
|
|
2019-05-03 09:18:30 -04:00
|
|
|
f1(0)
|
|
|
|
f1(1)
|
|
|
|
f1([])
|
|
|
|
f1([1])
|
|
|
|
|
2023-02-01 19:51:48 -05:00
|
|
|
|
2019-05-03 09:18:30 -04:00
|
|
|
# taking and returning a bool
|
|
|
|
@micropython.viper
|
|
|
|
def f2(x: bool) -> bool:
|
|
|
|
return x
|
2020-03-22 22:26:08 -04:00
|
|
|
|
|
|
|
|
2019-05-03 09:18:30 -04:00
|
|
|
print(f2([]))
|
|
|
|
print(f2([1]))
|
|
|
|
|
2023-02-01 19:51:48 -05:00
|
|
|
|
2019-05-03 09:18:30 -04:00
|
|
|
# converting to bool within function
|
|
|
|
@micropython.viper
|
|
|
|
def f3(x) -> bool:
|
|
|
|
return bool(x)
|
2020-03-22 22:26:08 -04:00
|
|
|
|
|
|
|
|
2019-05-03 09:18:30 -04:00
|
|
|
print(f3([]))
|
|
|
|
print(f3(-1))
|