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

  • Rename convert_intro as convert_try_this.  
  • Make the modifications shown below.
  • Save, and then flash the script into the micro:bit.
# 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()
  • Open the terminal.
  • Verify that the type of s is <class 'str'> and the type of n is <class 'int'>.