首页 > 代码库 > Python 学习5

Python 学习5

1. Global scope value can not be changed in function.

2. We can define a global variable in a function by using global.

3. Rules of using variable:

  • First start with the local scope, if any. If the variable is defined here, use the value.
  • Look at any enclosing scopes, starting with the innermost. These are "outside" local scopes. If the variable is defined in any of them, use the value.
  • Look in the global scope. If the variable is there, use the value.
  • Finally, look in the built-in functions.
  • If no value is found, an error will be thrown.

 

Regular Expression(for extract number from a long string):

1. 

Python 学习5