首页 > 编程语言 > 详细

python开发基础(三)数学函数与python函数

时间:2021-04-06 12:55:09      阅读:21      评论:0      收藏:0      [点我收藏+]
# 函数
def functions(x):
    """
    functions test
    """
    x += 1
    y = x ** 2
    return x, y


functions = functions(x=5)
# print(functions)


"""
def: 定义函数的关键字
function: 函数名
(): 参数,多个参数用逗号隔开
x += 1, y = x**2: 代码块的处理逻辑
return: 定义返回值
"""


# 例子
def function_1():
    # num = int(input(‘请输入密码:‘))
    num = 123
    yes = 密码正确!
    no = 密码错误,请重新输入!
    if num != 123:
        return no
    return yes


function_1 = function_1()
print(function_1)


# 函数参数
# 形参
def function_2(x, y):
    count_2 = x ** y
    return count_2


function_2 = function_2(3, 2)
print(function_2)


# 实参一一对应
def function_3(x, y, z):
    return x, y, z


function_3 = function_3(x=1, y=3, z=2)
print(function_3)


# 参数组 **字典 *列表
def function_4(x, *y):
    return x, y


def function_5(x, **y):
    return x, y


# function_4 = function_4(1, 2, 3, 4, 5)
function_4_1 = function_4(1, {1: 1}, {2: 2})
function_5 = function_5(1, name=Jack, age=18, adders=China)
# print(function_4)
print(function_4_1)
print(function_5)


# def functions(*, *args, **kwargs)
def function_6(x, *y, **z):
    return x, y, z


function_6 = function_6(1, 2, 3, 4, 5, 6, a=a, b=b)
print(function_6)

 

python开发基础(三)数学函数与python函数

原文:https://www.cnblogs.com/longloved/p/14620379.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!