查看: 1812|回复: 0

[教程] 【一网打尽】Raspberry Pi Week 8 – Day 2 (Python Function Parameters)

[复制链接]
  • TA的每日心情
    开心
    2016-8-4 10:56
  • 签到天数: 242 天

    连续签到: 1 天

    [LV.8]以坛为家I

    发表于 2015-3-29 16:10:02 | 显示全部楼层 |阅读模式
    分享到:
    Raspberry Pi Week 8 – Day 2 (Python Function Parameters)

    Function parameters in python are values that are passed to functions and these parameters are used within the function. For example if you are writing a simple calculator program that adds two numbers then you will need to pass two numbers so that the function can add the numbers.

    AddNumbers(10, 10)

    The result would be 20. Take a look at the example below.

    Firstly we will write a program that displays a message, adds two numbers and displays the result.

    Download simpleAddition.py

    #a simple program that adds two numbers and displays the result

    num1 = 10

    num2 = 10

    result = 0


    result = num1 + num2

    print(“The result is “, result)

    A quick run down of the program is in order. As always a comment is needed so that the reader of the program knows what it does.

    #a simple program that adds two numbers and displays the result


    Next 2 variables are created, num1 and num2. These variables both hold the number 10 and a result variable is used and is assigned at value of 0.

    num1 = 10

    num2 = 10

    result = 0

    The num1 and num2 variables are added together and the result is stored in the result variable.

    result = num1 + num2


    Finally the print function is used to display the result.

    (‘The result is ‘, 20)

    The next step will be to use our own functions to create the same result but with much cleaner program code. Before we do this it might be worth revisiting the print function which is the subject on the next days lesson.

    Download the PDF file for Week 8 – Day 2 – Python Function Parameters Day-2-Python-Function-Parameters (1).pdf (62.48 KB, 下载次数: 1)

    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /2 下一条



    手机版|小黑屋|与非网

    GMT+8, 2024-3-29 00:37 , Processed in 0.112102 second(s), 16 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.