Basic Python knowledge

Source: Internet
Author: User

1. Variables and values:
Python is a dynamic type language and does not need to declare the variable type in advance. The variable type is initialized at the moment of value assignment. Python variable names are case sensitive, that is, "case" and "case" are different variables. python is case sensitive.

2 digits:
Python has five basic types of numbers. INT (signed integer), long (long integer), bool (Boolean), float (floating point number), complex (plural ). It is worth noting that python's long integer type is much wider than the range of C. It is limited to the Total virtual memory of the user's computer. In future versions, it is very likely that python will not distinguish between integer and long integer, but will unify the two types into long integer. The type of plural is usually not directly supported in other languages. The support for plural is a personalized feature of Python.

3String:
Strings in Python are defined as character set combinations between quotation marks. Pair single quotation marks, double quotation marks, and three double quotation marks (three consecutive single or double quotation marks) can be used to represent strings. Three quotation marks support multiple rows. String supports index operators [] and slice operators [:]. For example, if X = 'abcde', the value of X [0] is 'A', and the value of X [4] is 'E '. In addition, Python supports negative index values. The value of X [-1] is 'E', which is the last element in the string sequence, the value of X [-2] is 'D', which is the second-to-last element in the string sequence. If you want to know more, you can seePython listThis one.

4. Comment "#"
The comment Statement of Python starts with "#" and ends with a line.CodeIt is very helpful for cooperative development, so we need to develop this good habit.

We hope that the above basic Python knowledge will allow you to understand the features of python in a short time. You have learned the basic knowledge.Python MySQL installation package 
Python search for Web keyword ranking Python code format problems Python OOP private Mechanism Python overload Python is Python Lambda 

5 code blocks and indent alignment
Python code blocks express code logic through indentation alignment, rather than using braces (from now on, say goodbye to the sacred braces war). Python supports tab indentation and space indentation, but PythonCommunityWe recommend that you use four spaces for indentation. You can also use tab indentation, but do not use mixed indentation symbols.

6; semicolon:
The semicolon (;) allows multiple statements to be written on the same line. The statements are separated by semicolons. These statements cannot start a new code block on this line. Although this can be done, Python does not advocate the use of ";" to write multiple statements in one line, which is not easy to read the code, and is not convenient for code extension and maintenance in the future.

7 OPERATOR:
Because python is a strongly typed language, if you are using an operator, for example, a plus sign (+), you must first unify the types of the two operands rather than directly performing operations. For example, an operand is a character type, if a number is used, python will report the following error: typeerror: Unsupported operand type (s) for +: 'int' and 'str'

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.