Python Quick Start 02-0529

Source: Internet
Author: User
Tags object serialization shallow copy

Data type conversions:

Show

Implicit

Dir (__builtin__) to view the built-in functions

Callable () can be used to test whether a function can be called

Dictionary: KV Set

{"A": +, "B": 545}

Each module has a built-in variable named __name__, which is adjusted to

If the module is imported, the value of __name__ is the module's name

If the module is executed directly, the value of __name__ is "__main__"

Class: Usually the custom type is used

Type: Built-in variable

Instance: instantiation

Classes: Data and methods

Data: Variables

Method: function

Classes: Instantiating objects

Comparison of two objects:

1. Value comparison: Whether the data in the object is the same

2. Identity comparison: Two variable names refer to the same object

3. Type comparison: Two objects are of the same type

Core data types

Numbers: Int,long,flocat,complex,bool

Character: Str,unicode

Listing: List

Dictionary: Dict

Tuples: Tuple

Files: File

Other types: Collection (set), Frozenset, class type, null (None)

Other file class tools: piping (pipes), FIFO (FIFOs), sockets

Type conversions:

STR (), repr (), and form

at (): Converts non-character data to characters

STR: The result of doing object serialization, casting

REPR: Do exact conversions, do not convert meta objects

Format

Int (): Convert to Integer

Float (): Convert to floating-point type

List (s): Convert string S to list

Tuple (s): convert string s to Narimoto group

Set (s): Converts a string s to a collection

Frozenset (s): Converts a string s to an immutable collection

Dict (d): Creates a dictionary based on the specified key-value pair, where D must be a tuple sequence (key,value)

Chr (x): Converts an integer to a character

Ord (x): Converts a character to an integer value

Hex (x): Converts an integer to 16 binary characters

Bin (x): Converts an integer to 2 binary characters

Oct (x): converting integers to 8 characters

Number type:

Python numeric literals: boolean, Integer, float, negative

True:1

false:0

is an immutable type

The math module enables advanced arithmetic operations

Sequence Type:

Character type

string literal: Enclose the text in single, double, or triple quotation marks: consistent before and after

If you want to use Unicode encoding, use the character u to identify before the character, such as U "mageedu"

Document string: The first statement of a module, class, or function is a character, and the string becomes a document string that can be referenced by using __doc__

Operator:

Index operator: [i] can use a negative number, that is, the value is inverted

Slice operator: [I:J]

Extended slices: [I:j:stride]

Support operations

Index, Slice, min (), Max (), Len (), etc.

Support operations

Object-owned operations

List:

Container type

An ordered set of arbitrary objects that access elements through an index, mutable objects

Heterogeneous, arbitrary nesting

Support in situ modification:

Modifies the specified index element, modifies the specified shard, deletes the statement, and the built-in method

L1 + L2: Merges two lists, returns a new list, does not modify the original list

L1 * N: Repeats L1 n times, returns a new list

In: Member relationship Judge character, usage obj in container

Not in:obj not in container

List parsing: []

List replication methods:

l1=[1,2,3,4]

Shallow copy

L2=l1

Deep copy

Import Copy

L2=copy.deepcopy (L1)

l2=l1[:]

Meta-group:

Expression symbol: ()

Container type

An ordered collection of arbitrary objects, which are accessed through an index, immutable objects, fixed lengths

Supports heterogeneous, nested

Common operations:

()

(1,)

(from)

T1 + T2

T1 * N

In

Not in:

Although the tuple itself is immutable, modifications to such elements do not return tuples if they are nested inside a mutable type element

Dictionary: Dict

Dictionaries are also referred to as associative arrays or hash lists in other programming languages

element access by key, unordered set, mutable type container, variable length, heterogeneous, nested

{Key1:value1,key2:value2,....}

{}: Empty dictionary

Dictionary copy: D2=d1.copy ()

D1.iteritems: Returns an iterator object Python QuickStart (02) _

Python Quick Start 02-0529

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.