Fourth Chapter function
4.1 Calling Functions
1, Python built-in a lot of useful functions, you can directly call
such as: ABS (), Max ()
2. Data type conversion
>>>int (' 123 ')
123
>>>str (123)
' 123 '
>>>bool (1)
True
3, the function name is
This article mainly introduces the default parameters in Python, this article explains the rationale of the default parameters, how to correctly use variable parameters and so on, the need for friends can refer to the
The subject of the article
Do
In C + +, you can specify a default value for the parameter. When a function call does not specify an argument that corresponds to a formal parameter, the default parameter is automatically used.The default parameter syntax is used with:(1) when a
The non-simple parameter is the new parameter syntax in ES6, which includes: 1. Default parameter values, 2. Remaining parameters, 3. Parametric deconstruction. The next step in this article is to ES7 why the use strict directive is forbidden in
Original blog: Reprint please indicate the source: http://www.cnblogs.com/zxouxuewei/1. The purpose of the default parameterC + + can define default parameter values for functions. Typically, when a function is called, the corresponding argument is
A function is a program segment that is reused. They allow you to give a name to a statement, and then you can run the block of statements any number of times in your program using that name. This is called a call function. We have used many of the
To invoke a function, you need to know the name and parameters of the function, such as an absolute function abs, which receives a parameter.
Documents can be viewed directly from the official Python
# default parameter # since we often calculate x2, it is possible to set the default value of the second parameter N to 2def power (x, n=2): s = 1 while n > 0: N = n - 1 s = s * x return s# So, when we call Power (5), it'
1. The purpose of the default parameter C + + can define default parameter values for functions. Typically, when a function is called, the corresponding argument is given for each parameter of the function. For example:void delay (int loops);
Passing Parameters
Some brief key points when a function passes a parameter:
The argument is passed by automatically assigning the object to the local variable name. All parameters are actually passed by pointers, and objects passed as
Import datetime as dt def log_time (message, Time=none): If Time is None: time=dt.datetime.now () print ("{0}: {1} ". Format (Time.isoformat (), message))
Recently I found in a python code a very nasty bug that was caused by the wrong use of
The default parameter value of the function, which is to give it an initial value at the same time as the parameter is defined. When calling a function, we can omit the parameter that contains the default value. That is, if the user specifies a
Details about five parameters of python functions and five parameters of python
(1) location parametersParameters are passed in by position when a function is called.
(2) default parametersThat is, the parameter value is given when the function is
1.1 parameters of the function1.1.1 Position Parameters>>> def power (x, N):... s = 1... while n > 0:... n = n-1... s = s * x.. return S...>>>>>>>>> Power (5,3)125Power (x,n),x and n are positional parameters, and when the function is called,
In-depth analysis of the parameters and scopes of functions in Python, python
PASS Parameters
Some brief key points when passing parameters in a function:
Parameter passing is achieved by automatically assigning an object to a local variable name.
Built-in functionsBuilt-in functions will check the parameters1 Print (ABS (-890)) # Seek absolute value 2 Print (Max (32, 63, 52342, 54)) # To find the maximum value 3 # type conversion function 4 Print (int (89.23)) 5 Print (Float (4))Custom
When I read "Python core programming" yesterday, I just saw the function section. so I would like to summarize all the currently available concentrated parameter types ^
(1) location parametersParameters are passed in by position when a function is
First, the default parametersIn C + +, you can specify a default value for the parameter. When a function call does not specify an argument that corresponds to a formal parameter, the default parameter is automatically used.The default parameter
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.