2. Basics of Python syntax

Source: Internet
Author: User
Tags natural string

2-1.python Constants and variables

A constant in Python refers to an immutable amount in the course of a program's operation, which is characterized by a binding that cannot be changed, and that the constants defined in Python need to be created using the object's method; Python's variables mainly refer to the amount that can be changed in the process of running the program;

2-2.python number and string

1. Learn the types of numbers:signed integer int long floating-point float Boolean type bool Complex type complex 2. What is a string? The character set quoted in Python is called a string, including a singlequotation marks, double quotes, three quotation marksThree kinds of quotation marks;single and double quotation marksRepresents a single-line string (in this case, a physical row), which can be used in a cross-reference, where single quotes can be enclosed in double quotes, and single quotes can be used in double quotes;three quotation marksUsed primarily for string wrap output, which can be three single quotation marks or three double quotation marks; 3. Escape character:escape character "\"Represents the next sameLogical LinePress only onePhysical LineOutputescape character ' \ n 'Represents the sameLogical LineTo divide multiplePhysical LineOutput 4. Natural string:If we have a string of strings, even if there are escape characters, we need to keep them as they are, without any processing, we can use natural strings, i.e.add R to the character before, as follows: As you can see, when using this natural string, the output is not wrapped even if the escape character is used in the string.when there is a natural string flag R, the escape character is output as is and does not work。 5. Duplicate output of string:When you need to repeat the output of a string, in addition to manually repeating the input string many times, you can also use therepeating operators for stringsSuch as: 6. Take substring:If you want to take a substring in a string, you want to do a substring operation, there are two sub-string operations, one isindex operation method [], the other isslicing Operation method [:], 2-3.python Data Types 1. Basic Data TypeThe most basic data types in Python are numbers and strings; 2. ListIn Pythonno concept of arrays, the closest concept to an array in Python isListAndmeta-group;Lists are used to store a series of elementsContainer,with[]represents Note:List elements are 0-based, and the elements in the table can be changed; 3, meta-groupTuple with()to express;the difference between the list and the tuple is: the elements in the table can be modified, and the elements in the tuple are not modifiable, only read; 4. CollectionThe Python collection has two main functions, one of which isBuilding Relationships, the other isEliminate duplicate elements; The format of the collection is: Set (Element) 5. DictionariesThe dictionary in Python is also calledAssociative ArraysUse{}Format: zidian={' name ': ' Xiaoli ', ' home ': ' Hubei ', ' like ': ' Music ' can be understood, the dictionary actually contains a whole thing, which contains specific information on various aspects The following example shows how todefine dictionaries, use dictionaries, add content to dictionaries: 2-4.python identifier 1. What is an identifier? Python is called an identifier when we are programming. 2. The naming principle of identifiers:The first character of an identifier must be a letter or an underscore, not a number or other, except the first letter, the other bits can be letters, underscores or numbers; identifiers are case sensitive; 3. Python keyword:Keywords refer to the system's own identifier with a specific meaning, commonly used: And, elif, Global, or, else, pass, break, continue, import, class, return, for, while, print 2-5.python Object 1. What is a Python object? In Python, everything is an object; Python's built-in object types are: numbers, strings, lists, tuples, dictionaries, collections, etc.; 2, pickle pickled:In Python, if some objects require persistent storage and do not lose the type and data of our object, we need toserialization of this object, after serialization, when we need to use, and then revert back to the original data, serialization of this process, we call pickle (pickled), the process of recovery is called anti-pickle pickling.

2. Basics of Python syntax

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.