python learning function

Function definition:

In can be used in Python def keyword to define functions and variables as each function also has a famous name, but naming naming rules are rules and variables are the same.

  • Repeat function may be used to define codes, organize and simplify
  • In general a function of a small feature in the actual development
  • A class is a big feature
  • The same function of the length of not more than one screen

1, reusable function is used

2, there is a routine defined functions, of course, you were ignorant of the child, it should function like this to write

You must first learn to write bare code and see where is the need for repeated use

Next, the code needs to be converted into reusable parameter, brought into the function

Function framework:

 

#_name_ is python in an implicit variable it represents the name of the module

# Only the name of the module directly executable python interpreter is _main_

Scope of variables:

  • Local variables local
  • Global Variables global
  • globals function returns a dictionary global variable, including all variables introduced
  • global: during the time of assignment to declare

E.g:

  • about locals () function returns the current position of all variables local to the dictionary type.

Exercise: Suppose college tuition this year is $ 10,000, and an annual growth of 5%, programming fees calculated after ten years and ten years from start to total four years of college tuition.

 

 

Guess you like

Origin www.cnblogs.com/wsq-qq/p/11348293.html
Recommended