Daniel finishing the most complete Python 0 basic introductory learning materials

Source: Internet
Author: User
Tags python list

Daniel finishing the most complete Python 0 basic introductory learning materials0Date: "2017-11-12 11:56" post Category: "AI" read: 3504 (the responsibility of the "Daniel finishing the most complete Python 0 basic introductory learning materials": Lao Wang) Abstract: Daniel finishing the most complete Python 0 basic introductory learning materials

Python data Type--digital

The Python Number data type is used to store numeric values.

The data type is not allowed to change, which means that if you change the value of the Number data type, the memory space will be redistributed.

var1 = 1 VAR2 = 10

You can also use the DEL statement to delete some number object references.

You can delete single or multiple objects by using the DEL statement

del var

Del Var_a, Var_b

Integer (INT)-usually referred to as an integer or integral, is a positive or negative integer, with no decimal points.

Float (floating point real values)-floating-point types consist of integral and fractional parts, and floating-point types can also be represented using scientific notation (2.5e2 = 2.5 x 102 = 250)

Complex numbers (complex numbers)-complex numbers are made up of real and imaginary parts, and can be represented by a + BJ, or complex (A, a, b), where both the real and imaginary part of a complex number are floating-point types.

Python also supports complex numbers, which consist of real and imaginary parts, and can be represented by a + BJ, or complex (a, b), where the real and imaginary parts of a complex number are floating-point

Python Number Type Conversion

Python math functions

Python random number function

Random numbers can be used in mathematics, games, security and other fields, but also often embedded in the algorithm to improve the efficiency of the algorithm and improve the security of the program.

Python contains the following common random number functions:

Python Trigonometric functions

Python Math Constants

Python data Type--string

The string is the most commonly used data type in Python. We can use quotation marks (' or ') to create a string.

Creating a string is simple, as long as you assign a value to the variable.

var1 = ' Hello world! ' var2 = "Python Runoob"

Python accesses a value in a string

Python does not support single character types, and one character is also used as a string in Python.

Python to access substrings, you can use square brackets to intercept strings

Python string update

You can modify a string that already exists and assign it to another variable

Python escape character

Python uses backslash () to escape characters when you need to use special characters in characters

Python string operator

Python string formatting symbols:

Formatting operator Auxiliary directives:

Python2.6 begins with the addition of a function str.format () that formats the string, which enhances the functionality of string formatting.

Python three-quote (triple quotes)

Three quotation marks in Python can be used to copy complex strings:

Python three quotes allow a string to span multiple lines, and the string can contain line breaks, tabs, and other special characters.

The syntax for a triple quotation mark is a pair of consecutive single or double quotes (usually paired).

Three quotes allow programmers to escape from the mire of quotes and special strings, keeping a small piece of string in the form of what is known as WYSIWYG.

A typical use case is that when you need a piece of HTML or SQL, it's very tedious to use a string combination to escape a special string.

Unicode string

Defining a Unicode string in Python is as simple as defining a normal string:

The lowercase "u" before the quotation mark indicates that a Unicode string is created here. If you want to add a special character, you can use Python's Unicode-escape encoding.

The replaced identity represents the insertion of Unicode characters (whitespace) encoded with 0x0020 at a given location

1 U ' Hello world! ' 2 U ' Hello world! '

Python string built-in functions

Python data Type--list

List is one of the most commonly used data structures in Python and other languages. Python uses brackets [] to parse the list

The sequence is the most basic data structure in Python. Each element in the sequence is assigned a number-its position, or index, the first index is 0, the second index is 1, and so on.

Sequences can be performed by operations including indexing, slicing, adding, multiplying, and checking members.

In addition, Python has built-in methods for determining the length of a sequence and determining the maximum and minimum elements.

A list is the most commonly used Python data type and can appear as a comma-separated value within a square bracket.

Data items for a list do not need to have the same type

Create a list by enclosing separate data items separated by commas in square brackets.

List1 = [' Physics ', ' Chemistry ', 1997, 2000];list2 = [1, 2, 3, 4, 5];list3 = ["A", "B", "C", "D"];
The list increases

The deletion of the list

Changes to the list

List of search

Python List script operators

The operands of the list to + and * are similar to strings. The + sign is used for the combined list, and the * number is used for repeating lists.

Python list interception

Python list Functions & methods

Python contains the following methods:

Python data type--tuple

A python tuple is similar to a list, except that the elements of a tuple cannot be modified.

Tuples use parentheses, and the list uses square brackets.

Tuple creation is simple, just add elements in parentheses and separate them with commas.

Create an empty tuple

Tup1 = ()

When you include only one element in a tuple, you need to add a comma after the element

Tup1 = (50,)

Creation of tuples

1 tup1 = (' Physics ', ' Chemistry ', 1997, N); 2 tup2 = (1, 2, 3, 4, 5); 3 Tup3 = "A", "B", "C", "D";

Tuples can use subscript indexes to access values in tuples

accessing tuples

element values in tuples are not allowed to be modified, but we can concatenate combinations of tuples

modifying tuples

The element values in the tuple are not allowed to be deleted, but we can use the DEL statement to delete the entire tuple

Delete a tuple

Tuple operators

As with strings, you can use the + and * numbers to perform operations between tuples. This means that they can be combined and copied, and a new tuple is generated after the operation.

Tuple index, intercept

Because tuples are also a sequence, we can access the elements at the specified location in the tuple, or we can intercept an element in the index as follows:

Tuples: L = (' spam ', ' spam ', ' spam! ')

No close delimiter

Arbitrarily unsigned objects, separated by commas, are tuples by default

Tuple built-in functions

Python data Type--dictionary

A dictionary is the only type of mapping in Python that stores data in the form of key-value pairs (key-value). Python computes the hash function of key and determines the storage address of value based on the computed result, so the dictionary is stored out of order and the key must be hashed. A hash indicates that a key must be an immutable type, such as a number, a string, a tuple.

The Dictionary (dictionary) is the most flexible built-in data structure type in addition to the list of unexpected python. A list is an ordered combination of objects, and a dictionary is a collection of unordered objects. The difference between the two is that the elements in the dictionary are accessed by keys, not by offsets.

A dictionary is another mutable container model and can store any type of object.

Each key value of the dictionary (key=>value) pairs with a colon (:) split, each pair is separated by a comma (,), and the entire dictionary is enclosed in curly braces ({}), as shown in the following format:

D = {key1:value1, key2:value2}

The key must be unique, but the value does not have to be.

The value can take any data type, but the key must be immutable, such as a string, a number, or a tuple.

A simple Dictionary instance:

Dict = {' Alice ': ' 2341 ', ' Beth ': ' 9102 ', ' Cecil ': ' 3258 '}

You can also create a dictionary like this:

Dict1 = {' abc ': 456}; Dict2 = {' abc ': 123, 98.6:37};

The increase in the dictionary

The deletion of the dictionary

The change of the dictionary

The dictionary Search

The cycle of a dictionary

Other operations of the dictionary

Dictionary built-in functions & methods

The Python dictionary contains the following built-in functions:

The Python dictionary contains the following built-in methods:

Writing a dictionary program

For loop: The user iterates through the contents of an object in order.

Enumerate: enumeration, for an iterative (iterable)/Ergodic object (such as a list, string), enumerate it into an index sequence that can be used to obtain both the index and the value

Range: Specify a range to generate a specified number

Key Words:Programming language Python Data Structure Physics technology

Daniel finishing the most complete Python 0 basic introductory learning materials

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.