We have seen built-in functions that take a variable number of arguments. For example range can take one, two or three arguments.

It is possible to write user-defined functions with optional arguments, too. For example here is a function that prints the most common words in a histogram:

If you provide one argument number gets the default value. If you provide two arguments, num gets the value of the argument instead. In other words, the optional argument overrides the default value.

If a function has both required and optional parameters, all the required parameters have to come first, followed by the optional ones.

from Thinking in Python

Optional arguments的更多相关文章

  1. 命名实参和可选实参 Named and Optional Arguments

    1. 利用“命名实参”,您将能够为特定形参指定实参,方法是将实参与该形参的名称关联,而不是与形参在形参列表中的位置关联. static void Main(string[] args) { Conso ...

  2. jquery function Optional Arguments

    1.javascript 选项散列对象 function Test(p1,p2,p3,p4,p5){ //do something } call: 参数可选 Test({ p1:value1, p2: ...

  3. Python高手之路【二】python基本数据类型

    一:数字 int int(整型): 在32位机器上,整数的位数为32位,取值范围为-2**31-2**31-1,即-2147483648-2147483647 在64位系统上,整数的位数为64位,取值 ...

  4. python基础

    内容概要: 一.python2 or python3 目前大多使用python2.7,随着时间的推移,python3将会成为python爱好者的主流. python2和3区别: 1.PRINT IS ...

  5. Python标准模块--argparse

    1 模块简介 你一定很奇怪Python是如何命令行中的变量的吧?argparse就是用来解决这个问题的,argparse是optparse的替代. 2 模块使用 2.1 开始 我发现解释一个编程的概念 ...

  6. DotNet 资源大全中文版(Awesome最新版)

    Awesome系列的.Net资源整理.awesome-dotnet是由quozd发起和维护.内容包括:编译器.压缩.应用框架.应用模板.加密.数据库.反编译.IDE.日志.风格指南等. 算法与数据结构 ...

  7. 读书笔记--SQL必知必会--Tips

    01 - 如何获取SQL命令帮助信息 官方手册 help 或 help command MariaDB [(none)]> help General information about Mari ...

  8. Python基础(二)

    本章内容: Python 运算符(算术运算.比较运算.赋值运算.逻辑运算.成员运算) 基本数据类型(数字.布尔值.字符串.列表.元组.字典.set集合) for 循环 enumrate range和x ...

  9. python-基本数据类型

    /int整数/ 如: 18.73.84 每一个整数都具备如下功能: class int(object): """ int(x=0) -> int or long i ...

随机推荐

  1. HDU 1796

    呃,我竟然傻了,同时被a且b整除的个数为n/(a*b). 其实应该是n/[a,b]才对,是他们的最小公倍数啊... #include <iostream> #include <cst ...

  2. 《从零開始学Swift》学习笔记(Day 46)——下标重写

    原创文章.欢迎转载.转载请注明:关东升的博客 下标是一种特殊属性. 子类属性重写是重写属性的getter和setter訪问器,对下标的重写也是重写下标的getter和setter訪问器. 以下看一个演 ...

  3. MyEclipse打包可运行的jar包

    详细步骤: Export... -> java -> Runnable JAR file Launch configuration:选择main方法所在的文件/类 Export desti ...

  4. 343D/Codeforces Round #200 (Div. 1) D. Water Tree dfs序+数据结构

    D. Water Tree   Mad scientist Mike has constructed a rooted tree, which consists of n vertices. Each ...

  5. iOS (封装)一句话调用系统的alertView和alertController

    前言: 本文仅作参考存留,请用新版封装:iOS 更加优雅便捷的UIAlertView/UIAlertController封装使用 UIAlertController是iOS8.0之后出来的新方法,其将 ...

  6. POJ 3044单调栈

    题意: 思路: 单调栈 // by SiriusRen #include <stack> #include <cstdio> using namespace std; stac ...

  7. 移动端fixed后 横竖屏切换时上部或下部出现空隙问题

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. springMVC下ajax获取后台参数直接走错误或者报406错误问题解决

    直接走错误: 返回的结果是否json化,直接返回非字符串的结果会走ajax的error函数. 报406错误: 我在学习springmvc过程中(我的项目是配置的后缀是.html),从controlle ...

  9. word-wrap与word-break的区别,以及无效情况

    两种方法的区别说明: 1,word-break:break-all 例如div宽400px,它的内容就会到400px自动换行,如果该行末端有个英文单词很长(congratulation等),它会把单词 ...

  10. sharding-jdbc,轻量级数据库分库分表中间件

    Sharding-JDBC是当当应用框架ddframe中,从关系型数据库模块dd-rdb中分离出来的数据库水平分片框架,实现透明化数据库分库分表访问.Sharding-JDBC是继dubbox和ela ...