print()
Micropython可以像Python一样使用print()输出想要的信息或变量,与Python不同的是,Micropython的输出是单片机通过与计算机连接的串口(USB线缆)输出到IDE上的,未通过串口与调试设备连接时不会输出,print()的语法和Python基本一致。
print('hello world!') #输出固定字符串【hello world!】
a=1
print(a) #输出变量内容【1】
print(a,'hello world!') #多字段输出,自动添加空格【1 hello world!】
print(f'hello world! {a} ') #f-string输出【hello world! 1】
input()
尽管我们在使用单片机时通常不使用input()输入,但是它也确实可用,只是他会阻塞程序运行,等待IDE输入完成并按下回车才会继续往下执行,所以我们一般不使用它,而是使用输入设备,比如按键/电位器来完成输入。
name = input("Name? ") # 带提示
n = int(input("How many blinks? ")) # 转整数
delay = float(input("Delay (s)? ")) # 转浮点
a,b= map(str,input('nums:').split(',')) # map() split() 可用