Python core Programming 2 The fourth chapter after class practice

Source: Internet
Author: User

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

Identity: The unique identity type of an object: the type of the object determines what type of value value the object can hold: The data item represented by the object 4-2 type. What does non-change (immutable) mean? What types of Python can be changed (mutable) and which are not? immutable (immutable) means that the value of an object is not allowed to be changed.
mutable type: list, dictionary. immutable types: Numbers, strings, and tuples.     Can be determined from the ID () whether it can be changed
4-3 type. Which Python types are accessed sequentially, and what are the differences between them and the mapping type?     strings, lists, and Ganso are accessed sequentially.    The sequence type refers to the elements within the container that are accessed in index order starting at 0. You can access one element or multiple elements at a time. Although a string is a simple type of text, it is also classified as a sequence type because it has the ability to access substrings in order.    The mapping type is similar to the indexed property of a sequence, but its index does not use sequential numeric offsets, its elements are stored out of order, accessed by unique keys, that is, the mapping type. It accommodates a collection of hash key-value pairs. 4-4 type (). What does the built-in function type () do? What is the object returned by type ()? Type () A function that detects the type of the object, and types () returns the object when the object is typed. 4-5 str () and repr (). What is the difference between the built-in function str () and repr ()? Which is equivalent to the inverse quotation mark (') operator?. STR () is committed to generating an object's readable string representation, and its return results are usually not available for eval () evaluation. Repr () and (") do exactly the same thing, they return an" official "string representation of an object, which means that in most cases the object can be re-obtained by an evaluation operation (using the built-in function eval ()).In short, the string of STR () output is friendly to the user, and the repr () output string is more friendly to Python. 4–6 objects are equal. What do you think is the difference between type (a) = = Type (b) and type (a) is type (b)? Why would you choose the latter? What does the function isinstance () have to do with this?
type (a) ==type (b) compares the value of the object to the object itself, type (a) is type (b) by the object Type property comparison, and Isinstance () is also compared by the object Type property 4-7 Built-in function dir (). In the second chapter of the exercises, we use the built-in function dir () to do several experiments, it takes an object, and then gives the corresponding properties. Please do the same experiment on the types module. Make a note of the types you are familiar with, including your knowledge of these types, and then note the types that you are not familiar with. In the process of learning Python, you will gradually

The "unfamiliar" type becomes "familiar".

4-8 lists and tuples. What is the same point for lists and tuples? What are the different points? Lists and tuples have the same point of sequential access, and the difference is that the list can be changed, and tuples cannot be changed.
4-9 Exercise, given the following assignment: A = ten
B = Ten
C =
d =
e = 10.0
f = 10.0
what is the output of the following expressions? Why? In Python, integer and string objects are non-mutable objects, and Python caches them very efficiently, causing us to think that Python should create new objects without the illusion of creating new objects. Therefore, returns True when the first two integers are compared, and returns false when the floating-point is compared

Python core Programming 2 fourth post-lesson exercise

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.