Use Python to implement a small airline ticket booking system (3)

Source: Internet
Author: User

Let's talk about the problems encountered here. First, we can't figure out whether to transfer references or objects at the beginning. (I don't know if it is reasonable to say this, but from the perspective of c ++, I think it will be simpler.) I have a list of flights in the airline category, so if I append a flight object to this list, and the next flight object changes, will the one in the corresponding company list change? The same question also appears in the seat list of the flight object and the seat list of the customer. later, I tried it and found that it would change. This is the transfer of reference. in simple python, we actually say:

When you create an object and assign it a variable, this variable is onlyReferenceThe object instead of the object itself! That is to say, the variable name points to the memory of the object stored in your computer. This is called the name-to-ObjectBind.

In fact, the address of the object is stored in the array. I think this is the same as that in java, except for the basic data type. For example:

A = 0

B =

A = 9

In this case, how much B is? Will B change with the change of? The answer is no.

Another example is:

A = 'A'

B =

A = 'B'

However, if you write:

Class:

Def _ init _ (self ):

Self. name =''

A = ()

B =

A. name = "nihao"

Print B. name

The result is nihao.

This indicates that non-basic types are passed references. Another example is a program,

Fun ():

A = 0

A = 9

Fun ()

Print

The answer is "9". This indicates that python is consistent with java in this respect.

The second problem is the code structure problem. I abstracted it into the following form:

Class:
Def _ init _ (self, mlist = []):
Self. mylist = mlist
Class B:
Def _ init _ (self ):
Self. P = None
Def setList (self, ):
Self. P =
A. mylist. append (self)

A1 = ()
A2 = ()

B1 = B ()
B2 = B ()

B1.setList (a1)
B2.setList (a1)

Print a1.mylist
Print a2.mylist

The printed results will surprise me ..... so far I have not figured out why ......... you can run it yourself ....... if you know this, make sure you comment and tell me about it !!!!! Kneeling !!!!

Related Article

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.