Python core programming 2 Chapter 4 after-school exercises, python after-school exercises

Source: Internet
Author: User

Python core programming 2 Chapter 4 after-school exercises, python after-school exercises

4-1 Python object. What are the three attributes related to all Python objects? Please briefly describe it.

Identity: Unique Identifier type of the object: The object type determines what type of value the object can save: data items represented by the object Type 4-2. What does immutable mean? Which types of Python are changeable and which are not?Immutable means that the object value cannot be changed.
Variable type: List and dictionary. Unchangeable type: Numbers, strings, and tuples. The id () can be used to determine whether it can be changed.
  Type 4-3. Which Python types are accessed in order, and what are their differences from the ing types?String, list, and ancestor are all accessed in sequence. Sequence type indicates that elements in the container are accessed in the index Sequence starting from 0. You can access one or more elements at a time. Although a string is a simple text type, it also belongs to the sequence type because it has the ability to access the substring in order. The ing type is similar to the index attribute of the sequence. However, its index does not use the ordered numeric offset value. Its elements are stored unordered and accessed by a unique key, that is, the ing type. It contains a set of hash key-value pairs. 4-4 type (). What is built-in function type? What is the object returned by type?Type () checks the type function of the object, and the type of the object returned by type. 4-5 str () and repr (). What is the difference between the built-in str () and repr () functions? Which one is equivalent to the inverse quotation mark ('') operator ?.Str () is used to generate a readable string representation of an object, and its return results cannot be used for eval () evaluate. Repr () and ('') do exactly the same thing. They return an object's" official "string representation, that is to say, in most cases, this object can be re-obtained through evaluate (using the built-in function eval. In short, the string output by str () is user-friendly, and the string output by repr () is python-friendly. 4-6 objects are equal. What is the difference between type (a) = type (B) and type (a) is type (B? Why the latter? What is the relationship between the isinstance () function and this function?
Type (a) = type (B) compares the value of the object rather than the object itself. type (a) is type (B) compares the object type attributes and isinstance () also through object type Property Comparison 4-7 built-in function dir (). In the exercises in Chapter 2, we have done several experiments with the built-in function dir (), which accepts an object and then gives the corresponding attributes. Perform the same experiment on the types module. Write down the types you are familiar with, including your understanding of these types, and then write down the types you are not familiar. In the process of learning Python, you must gradually

The "unfamiliar" type becomes "familiar.

  4-8 lists and metadata groups. What are the similarities between a list and a group? What are the differences?The same points of a list and a group are sequential access. The difference is that the list can be changed, and the tuples cannot be changed.
4-9 exercise, given the following values: A = 10
B = 10
C = 100.
D = 100
E = 10.0
F = 10.0
What is the output of the following expressions? Why?In python, integer and string objects are immutable, and Python caches them very efficiently, causing us to think that when Python should create a new object, it does not have the illusion of creating a new object. Therefore, true is returned when the first two integers are compared, and false is returned when the floating point is compared.

 

 
Which of the following is the Python core programming (version 2nd) and Python learning Manual (version 4th) that is more suitable for beginners and practical?

I used core programming at the time. If you want to learn what you want, you can search for information on the Internet. These two books are the most basic syntax. For example, python cookbook.

Which of the following is the Python core programming (version 2nd) and Python learning Manual (version 4th) that is more suitable for beginners and practical?

The python learning manual is better, and the python core programming book is not good! It is best to read the official documentation. Of course, it is better to use English.

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.