Python Quick Retriever (1) Type and Function

xiaoxiao2021-03-06  67

Learning Python has some days, some things and C , Java does have a big difference, so I will organize some things to organize it. Do not ask for it. First, from variables and functions, gradually finish.

"Everything is Object" is a principle of Python. Any type, variable, function, module are both objects. 1. Basic Type 1. Integer: 2. Floating-Point (FLOAT): (1 == 1.0) is a true value 3. Multiple (complex): c = 1 5J == C1 = Complex (1, 5) is a true value 4.None type: indicates an error 5. Logical expression: logical operator: (level below the comparative operator) A and B # and. A is a false, returning to the value of expression a. A is true, returning the value of expression b. A or b # or. The expression of A, B is true, the result is a; # if it is a true value, return the value of true value expression; # is a fake (null value and 0), the result is B (0 or empty value). NOT # is not. Not a == b is not (a == b), the comparison operator: x == y #x is equal to Y x! = y #x does not equal y x> y #x is greater than y x = y #x is greater than or equal to Y x <= y #x is less than or equal to Y AND-OR skills (implement C language BOOL? A: B) >>> a = ">>> b =" second ">>> BOOL = 1 >>> (BOOL AND [A] or [b]) [0] # 注意 [] The intention is to ensure that the expression of A is TRUE, does not affect the calculation result 2, function 1. Function definition deffunction_name

):

# Code block to indent the return ... # function There is no return value type definition, Return can return any type, or no return value # function can nested a function 2. The parameter transfer function parameters of the function do not need to be defined. If the type is not Match, the function code can be thrown. The function parameter is passed by address reference. However, due to local namespace, it seems that the simple variable is passed by value. Default parameter (optional parameters): Def setPosition (name, height = 170, weight = 70): >>> setPosition ("My Cup") variable quantity parameters: (Think about MAIN in C language (int Argc) Char * argv [], printf ()) Press TUPLE mode to pass multiple parameters (any parameter): DEF Printf (Format, * arg): # * arg must be the last parameter. # * Indicates that any parameters are accepted, and the variables after it generate TUPLE to the function >>> Printf ("Hello", "My", 2, ["DOG", "Pig"]) Press Dictionary to pass multiple Parameters (any name parameters): DEF printf (Format, ** keyword): # ** Indicates the parameters of any key, value formula, generate a word code to function >>> PRINTF ("Dict Format", One = 1 , TWO = 2, Three = 3) # This example is ["One", "Two", "Three"], VALUES is [1, 2, 3] When mixing, order is sorted as: fixed parameters, lack Value parameters, * arg, ** keyword. 3. The attribute function of the function is also an object. The function name can assign a value to other variables like normal variables (the meaning of the function pointer of the C language) __doc__ attribute, the first expression defined by the # function is Str, it is __doc__ Can make help tips. 4. Function Function Follow the LGB principle (call priority to local, global, buildin) 5.Lambda function function function programming language is very basic, and can see the anonymous function of a line. >>> f = lambda a, b: a b # equivalent to DEF F (A, B): Return A B 6.Python Some built-in functions (only about object properties, type conversion, etc. Listed) Type () # Types of the value and variables.

转载请注明原文地址:https://www.9cbs.com/read-119320.html

New Post(0)