十. Python基础(10)--装饰器 1 ● 装饰器 A decorator is a function that take a function as an argument and return a function. We can use a decorator to extend the functionality of an existing function without changing its source. Decorators are syntactic sugar.…
一.三元运算符 本质是if--else--的语法糖 前提:简化if--else--的结构,且两个分支有且只有一条语句 案例: a = 20 b = 30 res = a if a > b else b # 求最大值 print(res) res = a if a < b else b # 求最小值 print(res) 三元运算符的结果不一定要与条件有直接性关系 res = 'b为小值' if a > b else 'a为小值' print(res) name = input("…
基本数据类型补充: set 是一个无序且不重复的元素集合 class set(object): """ set() -> new empty set object set(iterable) -> new set object Build an unordered collection of unique elements. """ def add(self, *args, **kwargs): # real signature un…
一.数学定义的函数与python中的函数 初中数学函数定义:一般的,在一个变化过程中,如果有两个变量x和y,并且对于x的每一个确定的值,y都有唯一确定的值与其对应,那么我们就把x称为自变量,把y称为因变量,y是x的函数.自变量x的取值范围叫做这个函数的定义域 例如y=2*x. python中函数定义:函数是逻辑结构化和过程化的一种编程方法. python中函数定义方法: def test(x): "The function definitions" x+=1 return x def:…