pdf-icon

UIFlow Guide

UIFlow 1.0 Blockly

Event

Unit

UIFlow 1.0 Project

Functions

案例程序

定义两个函数,传入参数进行简单运算

from m5stack import *
from m5ui import *
from uiflow import *

x = None
y = None
result = None

# Describe this function...
def func(x, y):
  global result
  if x < y:
    print(x + y)
  else:
    print(x - y)

# Describe this function...
def mathfuc(y, x):
  global result
  if x < 0:
    return y - x
  return x + y

func(2, 3)
result = mathfuc(10, 5)

功能说明

def func(x, y):
  global result
  if x < y:
    print(x + y)
  else:
    print(x - y)
  • 创建一个函数,可设置参数,函数没有返回值
def mathfuc(y, x):
  global result
  return x + y
  • 创建一个函数,可设置参数,函数返回值
if x < 0:
    return y - x
  • 在函数中运行简单的 if 逻辑运算,结束该函数运算并返回一个值
On This Page