廖雪峰网站:学习python函数—定义函数(二)

def my_abs(x):
    if x >= 0:
        return x
    else:
        return -x

print(my_abs(-99))

# 空函数
def nop():
    pass

# 参数检查
def my_abs(x):
    if not isinstance(x, (int, float)):
        raise TypeError("bab operand type")
    if x >= 0:
        return x
    else:
        return -x



# 返回多个值

import math

def move(x, y, step, angle= 0):
    nx = x + step * math.cos(angle)
    ny = y - step * math.sin(angle)
    return nx, ny

n = my_abs(-20)
print(n)

x, y = move(100, 100, 60, math.pi/6)
print(x, y)
原文地址:https://www.cnblogs.com/qy1234/p/9362487.html