2025年04月07日
MicroPython被设计为能够运行于单片机或者微控制器上。对于熟悉常规计算机编程的程序员来说,这些设备往往具有许多硬件上的限制。具体来讲,其可用的RAM资源和“硬盘”资源(Flash存储器)均十分有限。该手册提供了一些方法以尽可能充分地利用这些有限的资源。因为MicroPython可运行于许多不同架构的单片机上,下面这些方法将力求通用。必要的话,你可以参考特定平台相关的文档以获取更多更详细的信息。
2025年04月07日
# 该函数有名称,名称是add
def add(x, y):
return x + y
# 改函数没有名称属于匿名函数,也叫lambda表达式
lambda_add = lambda x, y: x + y
if __name__ == '__main__':
print(add(1,2))
print(lambda_add(1,2))
2024年08月07日
Python是一个非常容易上手的编程语言,它的语法简单,而且功能强大,非常适合初学者学习,它的语法规则非常简单,只要按照规则写出代码,Python解释器就可以执行。
2024年08月07日
对于任意给定的四张扑克牌,计算是否有赢得24点游戏的方法(即使用加、减、乘、除四则运算凑成24的方法);如果有的话,列出所有可能的方法。
【24点游戏规则】
在大小王以外的52张牌中,任意抽取其中4张牌。如果通过加、减、乘、除四则运算(可加括号)的方法,将抽到的4张牌算成24,则为胜利;每张牌都必须使用,且只能使用一次。
2024年08月07日
整理Python中常用的函数
使用ast模块中的literal_eval函数来实现,把字符串形式的list转换为Python的基础类型list
2024年08月07日
今天的Python学习教程想跟大家说一下exec执行函数
exec 函数功能:执行储存在字符串或文件中的 Python 语句,相比于 eval,exec可以执行更复杂的 Python 代码。
英文解释
This function supports dynamic execution of Python code. object must be either a string or a code object. If it is a string, the string is parsed as a suite of Python statements which is then executed (unless a syntax error occurs). If it is a code object, it is simply executed. In all cases, the code that’s executed is expected to be valid as file input (see the section “File input” in the Reference Manual). Be aware that the return and yield statements may not be used outside of function definitions even within the context of code passed to the exec() function. The return value is None.