Step by step, learn python (6)-Abstraction

Source: Internet
Author: User

1. Convert string to numeric

Import locale

Locale. atoi (str)

2. Create a function

A function can be called (may contain parameters) to execute a behavior and return a value.

>>> Import math

>>> X = 1

>>> Y = math. sqrt

>>> Cllable (x)

False

>>> Callable (y)

True

Define a function using def

Def hello (name ):

Return 'hello, '+ name + '! '

In this way, a hello function is defined.

3. Record Functions

Def square (x)

'Calculates the square of the number x .'

Return x * x

The document can be accessed as follows

Square. _ doc _

'Calculates the square of the number x .'

The built-in function help is very useful. You can obtain the function information in the interactive interpreter.

Help (square)


4. Keyword parameters and default values,

5. Collect Parameters

Def print (* param)

* Before the parameter, place all values in a single tuple.

6. Reversal Process

7. Scope

In addition to the global scope, each function creates a scope.

8. Recursion

Function calls are called recursion.



Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.