Try This: Check Variable Type
Let’s try changing some statements to check the data types of s and n. This can come in handy when you want to want your script to know for sure what it is receiving from another device.
Example script: convert_try_this
- Change project’s name from convert_intro to convert_try_this.
- Make the changes shown below.
- Save the modified script.
- Click the Send to micro:bit button.
# convert_try_this
from microbit import *
sleep(1000)
s = "1234"
n = 1234
print("s =", s)
ts = type(s) # <- change
print("Type of s: ts =", ts) # <- change
print()
print("n = ", n)
tn = type(n) # <- change
print("Type of n: tn =", tn) # <- change
print()
- Check the results in the serial monitor.
- Verify that the type of s is <class ’str’> and the type of n is <class ’int’>.
