day4 function built-in function module

Function parameters

variable parameter

  

 

 

 * Plus a variable ago, called the variable parameter or parameters. Not limiting parameters when the number of transmission parameters (may not pass or multiple pass), the parameter in one tuple; many parameters when a variable parameter, typically used to write * args.

 

 

 Variable parameter exists, the value is not passed to pass the specified value.

Keyword arguments

  

 

 

   * Before the variable is incremented by two when the transmission parameter transmitted in the form of key-value, into the dictionary as transmission parameters. You can not pass parameters. Generally written ** kwargs.

When four parameters together define a certain sequence

 

 

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

Cyclic sequence of parameters, can be used * unpacking, after unpacking the number to be consistent with the number of parameters.

If the transmission parameter intuitive dictionary is d4 = { 'word': 123, 'country': 999}, the key for the dictionary and reference consistent shape. t1 (** d4) returns a value of 123,999 

 Built-in functions

  input()   print()   len()  type()  str()  tuple()  set()  list()   dict()

  all (l) l = [1,3,9] # iteration object list if there are true returns true. any (l) # iterables If a value which is true is true

  bin (888) # turn to a decimal to binary bool ( 's') # converts a Boolean object to a type oct () # converted into digital octal

  chr (35) # corresponding digital printing ascii dict (a = 1, b = 2) # transfected into a dictionary l = [1,2,3,4,5,6,7,8,9,10] def t ( num): if num% 2 == 0:. return true l2 = list (filter (t, l) is filtered by the function value of l is true returns filtered data list (map (t, l)) is put. l data into execution function, false returns None, true true is returned. each return

   Ordering the sorted (D)    D = 'akkk42', a return value. Built-in sort. Dictionary example, strings, not like l.sort tuple list () changing the order of l, does not return a value. The method of this sort, use sorted (d) to sort

  max ([1,3,77]) takes the maximum value min () takes a minimum value    

  round (3.134,2) retention of decimal places

  Dir printing method can be called incoming object (S)    S = 'KKK' transmission is a string, the string is to see the calling method. See the other corresponding transmission method

  eval () and exec () are executed python code

  eval () # python code execution, only perform simple data type definitions and calculation. The equivalent of eliminating the string to run

 

 --------------------------------------------------------------------------------------------------------------------------------------

  exec () # python code execution, versatile, can perform complex.

If there is a python file, and now want to take over the operation. Code execution

f = open('a.txt',encoding = 'utf-8')    result = f.read()

exec (result) # operation code file

 

 ------------------------------------------------------------------------------------------------------------

zip () with the number of cycles list. To achieve with zip.

 

 

 -----------------------------------------------------------------------------------------------------------

Module

  1. A module is a python file write their own python files; a standard module, python comes; third-party modules

  installation:

    pip install xxx # install pip uninstall xx # uninstall pip install xx -U # Update pip freeze> Export .txt # third-party modules installed third-party modules pip install -r third-party modules .txt # read module, the batch file from inside installation

    pip problem: 1, pip command does not exist, the scripts under the installation of python adding an environment variable 2, pip pip at the time useless python directory, use the command know where the other pip, replaced by other names

  Installation Manual (the downloaded file to install) an absolute path ending behind whl pip install /Users/PyMySQL-0.9.3-py2.py3-none-any.whl # whl file 2, tar.gz end 1. 2. unzip on the command line into the unzipped directory 3. Run python setup.py install

  If you have multiple versions of python 1.python3 -m pip install xpinyin python2 -m pip install xpinyin 2. Locate the following versions of the scripts directory on the computer, pip each revised to pip2 / pip3           

  Sequence introduced into the module 1, the current directory to find 2, import sys print (sys.path) sys.path is a sequence sys.path.append (r 'module path') insert (0, r 'module path') into the library the forward position. Put the module into the substance of the module library database import module is: the essence import module is to change the module from top to bottom over the implementation of import datetime as f aliases from the module (module name) import a, name print (name) a () directly

 

 

 -----------------------------------------------------------------------------------

if __name__ == '__main __': # purpose of this line of code is written test modules can run down here, but this module is called, it will not execute this code below

       print (name) # fast play, main

       a()       

--------------------------------------------------------------------------------------

Guess you like

Origin www.cnblogs.com/11-pythong/p/11710607.html