Resources:
1. Basic Python Tutorial
2. http://www.runoob.com/python/python-functions.html
3. http://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000
4. http://www.runoob.com/python/python-modules.html
5. http://www.pythoner.com/
6. http://blog.csdn.net/leexide/article/details/39908279
? function
The parameters of Python are all reference passes.
The function syntax is as follows:
def functionname (Parameters): " Function _ Document string " function_suite return [expression]
Instance:
def printme (str): " print an incoming string to a standard display device " Print Str return
Python supports default parameters and variable length parameters, and the default parameters are defined and used with other programming languages. Examples of the use of indefinite length parameters are as follows:
#!/usr/bin/python#-*-coding:utf-8-*- #Writable Function DescriptiondefPrintinfo (arg1, *vartuple):"Print any parameters passed in" Print "Output:" Printarg1 forVarinchvartuple:Printvarreturn; #Call the Printinfo functionPrintinfo (10);p Rintinfo (70, 60, 50);
Python uses a lambda expression to create an anonymous parameter:
Lambda Syntax:
Lambda [Arg1 [, Arg2,..... argn]]:expression
Instance:
Lambda x, y = 5:x + ysum (3)
? Module
A module is a file that holds Python code (for example,. py) and is also a Python object with a random name attribute used to bind or reference. Where functions, classes, and variables can be defined, as well as executable code.
Import statement Syntax:
import module1[, module2[,... Modulen]
From...import statement Syntax:
from import name1[, name2[, ... Namen]]
from Import *
Use of global variables:
# !/usr/bin/python # -*-coding:utf-8-*- =def Addmoney ( ): Global money print Moneyaddmoney ()print money
The Dir (module_name) function returns a list of all modules, variables, and functions that are defined in a module.
The Globals () and locals () functions return the names of global or local command spaces, respectively.
Reload (module_name) function, re-import a module.
? Package
A package is a folder that contains at least __init__.py files.
Python Basic Learning Notes (11) Functions and modules