zoukankan      html  css  js  c++  java
  • 笨办法18命名、变量、代码、函数

    源代码如下:

     1 #coding: utf-8
     2 # this one is like your scripts with argv
     3 def print_two(*args):
     4     arg1, arg2 = args
     5     print "arg1: %r, arg2: %r" % (arg1, arg2)
     6 
     7 # ok, that *args is actually pointless, we can just do this
     8 def print_two_again(arg3, arg4):
     9     print "arg3: %r, arg4: %r" % (arg3, arg4)
    10 
    11 # this just takes one argument
    12 def print_one(arg5):
    13     print "arg5: %r" % arg5
    14 
    15 # this one takes no arguments 
    16 def print_none():
    17     print "I got nothin'."
    18 
    19 
    20 print_two("Zed1","Shaw1")
    21 print_two_again("Zed2","Shaw2")
    22 print_one("First!")
    23 print_none()

    运行结果: 
    这里写图片描述

    注:*args中,*表示将所有参数放在一个列表里


    加分习题¶

    函数定义是以 def 开始的吗? (√) 
    函数名称是以字符和下划线 _ 组成的吗? (× 字母、数字、下划线,不能以数字开头) 
    函数名称是不是紧跟着括号 ( ? (√) 
    括号里是否包含参数?多个参数是否以逗号隔开? (√) 
    参数名称是否有重复?(不能使用重复的参数名) 
    紧跟着参数的是不是括号和冒号 ): ? (√) 
    紧跟着函数定义的代码是否使用了 4 个空格的缩进 (indent)? (√) 
    函数结束的位置是否取消了缩进 (“dedent”)? (√)


    ‘运行函数(run)’、‘调用函数(call)’、和 ‘使用函数(use)’是同一个意思

  • 相关阅读:
    Linux手动分区步骤
    Vue到底是怎样个框架?
    MongoDB
    25、正则表达式
    24、模块
    21、三元表达式、列表解析、生成器
    Linux 软件包 管理
    CentOS7.5---7.9 中文字体匹配错误 fontconfig-2.13.0
    Ubuntu14.04下Git安装与使用
    Zabbix3.4 安装配置
  • 原文地址:https://www.cnblogs.com/p36606jp/p/7648208.html
Copyright © 2011-2022 走看看