Python (2)

Source: Internet
Author: User

First, Python is a strongly typed language:

1, two objects comparison:

(1), Identity (memory address): Two object references are the same.

ID (a) ==id (b) or A is B

(2), Value: Two object data is equal.

A==b

(3), type: Two objects are of the same type.

Type (a) is type (b)


2. Core Data type:

(1), Number: Int,long,float,complex,bool

(2), character: Str,unicode

strings can be defined in single quotes, double quotes, and three quotation marks, except that three quotation marks support line breaks.

Example: >>>str1=u "Hello"

>>>type (STR1)

Unicode

(3) Lists: List

A, the list operation contains the following functions:

A, CMP (List1, List2): Compare two elements of a list

b, Len (list): Number of list elements

C, Max (list): Returns the maximum value of a list element

d, Min (list): Returns the minimum value of the list element

E, List (seq): Convert tuples to lists

B. The list operation contains the following methods:

A, List.append (obj): Add a new object at the end of the list

B, List.count (obj): Count the number of occurrences of an element in a list

C, List.extend (seq): Append multiple values from another sequence at the end of the list

D, List.index (obj): Find the index position of the first occurrence of a value from the list

E, List.insert (index, obj): Inserting an object into a list

F, List.pop (Obj=list[-1]): Removes an element from the list (the last one by default), and returns the value of the element

G, List.remove (obj): Removes the first occurrence of a value in a list

H, List.reverse (): Reverse List of elements

I, List.sort ([func]): Sort the original list

(4), Dictionary: Dict

(5), tuple: tuple

(6), Files: File

(7), set: Set

(8), class type

(9), None


3. Type conversion:

(1), str (s), repr (s), format (s): Converts non-character s to characters.

(2), int (s): converts s to integers.

(3), float (s): converts s to floating-point numbers.

(4), list (s): convert S to list.

(5), tuple (s): converts s to tuples.

(6), set (s): Converts S to a collection.

(7), Dict (d): Create a dictionary, where D must be a tuple sequence (k,v).


Second, the document string:

When the first statement of a module, class, or function is a string, the string becomes a document string that can be referenced using the __doc__ property.

Python (2)

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.