Python function basicsA. function1. Introduction to FunctionsFunctions are well-organized, reusable pieces of code that are used to implement a single, or associated function.Functions can improve the modularity of the application, and the reuse of
1. A function defined inside a class is an implicit inline function.2. Because the purpose of this is always pointing to the "this" object, this is a constant pointer and we are not allowed to change the address saved in this.3. Constant member
Reference: http://www.weixueyuan.net/view/6341.htmlSummarize:The constructor for the default parameter, whose default argument must be placed at the end of the parameter list.It is best not to use the overloads of constructors and constructors with
1. If the first argument of a constructor is a reference to its own class type, and any additional parameters have default values, this constructor is a copy constructor. The first parameter of a copy constructor must be a reference type (otherwise
Each specific problem has specific implementation methods, and for the same class of problems, different concrete methods can be abstracted into this kind of method, when given a specific input, this kind of method will become applicable to a
The basic idea of a class: data abstraction and encapsulation. Data abstraction is a programming technique that relies on interfaces and implements separation. The interface of a class includes the actions that the user can perform, and the
Python3 functionFunctions are well-organized, reusable pieces of code that are used to implement a single, or associated function.Functions can improve the modularity of the application, and the reuse of the code. You already know that Python
Add by ZHJ: The Python document clearly explains how the default parameters work, as follows"Default parameter values are evaluated when the function definition is executed. This means the expression was evaluated once when the function was defined,
The function can give the default parameter value in advance when declaring it, and if the argument is given, the actual parameter value is used, otherwise the default value is given beforehand.int Add (int5,int6return x + y;} int Main () { Add
I. Functions and processes1, Python only function no process>>> def hello ():Print (' Hello fishc! ')>>> temp = Hello ()Hello fishc!>>> Temp>>> Type (temp)>>>Explanation: Hello is assigned to temp, and the value returned by individual temp is none2.
The parameters of the function are divided into:1. Required Parameters2. Keyword parameters3. Default parametersRequired ParametersThe most basic feature is that the parameters that we define in the function's argument list must be passed.def Add (x,
GetAttr (object, name[, default]), valueGet A named attribute from an object; GetAttr (x, ' Y ') is equivalent to x.y.When a default argument is given, it's returned when the attribute doesn ' tExist Without it, an exception was raised in the
1. PrefaceFunctions are well-organized, reusable pieces of code that are used to implement a single, or associated function. Functions can improve the modularity of the application, and the reuse of the code.2. Definition of functionsThe following
1.publish2.update Print_lolPs:For Step 1.Write the code in to a py file. Put the py file into a folder named Nester. New a py file named ' Setup ' and the content as below:Setup (name='Nester', Version='1.0.0', Py_modules= ['Nester'],
http://www.douban.com/note/134971609/PEP8 Python Coding SpecificationA code orchestration1 indent. Indentation of 4 spaces (the editor can do this), no tap, no mix of taps and spaces.2 The maximum length per line is 79, the line break can use
PEP8 Python Coding SpecificationA code orchestration1 indent. Indentation of 4 spaces (the editor can do this), no tap, no mix of taps and spaces.2 The maximum length per line is 79, the line break can use backslashes, preferably with parentheses.
In python, as the default parameter must be immutable object, if it is a mutable object, there will be problems, a little attention, will be transferred into traps, especially beginners, such as I (┬_┬). Let's look at an example.1 defAdd
Why do you use a functionNow the python session has a big event, Len Method suddenly can't directly use ...Let you calculate the length of ' Hello World ', how do you calculate?This requirement is not difficult for you now, let's write it together.S1
# The value of the default parameter is passed to the function at the beginning of the definition, # will not be modified in the subsequent revisions. # The value of the default parameter must be placed in the last face of the positional 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.