Python difficulty record

Source: Internet
Author: User

1. Classes and objects:

1. Class object, instance Object 2. Class member, instance member 3. Class functions, instance functions ----------need to understand the previous relationship, can call each other, scope

Problem:

#类内
#1. Can I access instance properties in a class method?No way
#2. class method Total Access Modify instance propertiesCls.country
#3. Can I access class properties in an instance method?                            Modify class properties? Yes, invalidSelf.county
#4. Accessing modified instance properties in instance methodsSelf.a
#类外
#1. Can instance objects access class properties? Modify class properties?                           lang=  
#2. Can the class object access instance properties?                           &NBSP ;                       no
#3. Can the instance object access the class method?                          ,         &NB Sp                 It is possible to modify class properties #4 through the class method. Can class objects access instance methods?                           &NBSP ;                       no

< Span lang= "en-US" > < Span lang= >2.python variables and storage

< Span lang= "en-US" > < Span lang= "en-US" > (go from http://www.cnblogs.com/Eva-J/p/5534037.html)

Then understand the assignment of variables, shallow copy, deep copy

1. Assigning values to variables:

Assignment of 1.str

2. Assignment of data structure

2. Shallow copy:

A shallow copy will only copy one layer when the Sourcelst list changes, the LST memory address stored in the COPYLST does not change, so when LST changes, the Sourcelst and copylst two lists change. This happens in dictionaries, list sets, dictionary sets, list sets, and nested lists of complex data structures, so when our data types are complex, it's very careful to use copy to make shallow copies ...

3. Deep copy :

A deep copy completely duplicates all the data associated with the original variable, producing exactly the same set of content in memory, in which we make any modification to one of the two variables without affecting the other variables

3. Parameters of the function:
    • 1. Common parameters: When you pass a parameter, you need to pass the parameter number as defined by the function, and type
    • 2. Default parameter: The parameter is written on the default value, and must be placed at the end of all parameters
    • 3. Dynamic Parameters:
      • def func1 (*args) accepts multiple parameters, internally automatically constructs tuples, adds * before sequence, and constructs incoming parameters as a tuple Note: fun () argument after * must is an iterable, not int: arrays, strings, and lists are all iterable.
      • def FUNC2 (**kwargs) receives multiple parameters, internally automatically constructs the dictionary, the sequence is pre-added * *, the dictionary is passed directly
        def func3 (*args,**kwargs): Accepts multiple parameters, which can be used to construct tuples automatically, and to construct dictionaries automatically.

4. Function return: Returns multiple values, returned in tuples

Example:

def fun1 (*arg):

Print (ARG)

a=[1,2,3,4,5]

FUN1 (*a)----> Output is: (1,2,3,4,5) pass the values in list A as elements of a tuple

FUN1 (a)----> output: (1,2,3,4,5],) pass List A as a whole as an element of a tuple

  

def fun1 (*arg):

Print (ARG)

b=[1,2,3,4,5]

C= ' Anna '

FUN1 (b,*a)----> Output results are: (1,2,3,4,5, ' Anna ')

FUN1 (b,a)----> Output results are: ([1,2,3,4,5], ' Anna ')

It is important to note that the parameters must be *args before the **kwargs is the same.

Python difficulty record

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.