This article is the first one. There are four articles in total to lay the foundation of Python
There are four types of numbers in python: integers, long integers, floating point numbers and complex numbers.
String (sequence of characters)
'\'
r"this is a line with \n"
, then \n
will be displayed, not a line break. unicode
strings, prefixed with u or U, such as u"this is an unicode string"
. Naming of identifiers
Any "thing" used in a python program becomes an "object".
Python assumes that each physical line corresponds to a logical line. For example: print( "Hello World" ) is a physical line, and Python hopes that each line has only one statement , because it looks more readable.
If you want to use more than one logical line in a physical line, then you need to use a semicolon (;) to specifically indicate this usage. Semicolon Indicates the end of a logical line/statement.
For example:
count = 5print ( "count" )复制代码
is equivalent to the following statement:
count = 5;print ( "count" );复制代码
Of course it can also be written as the following:
count = 5 ; print ( "count" );复制代码
can even be written like this:
count = 5 ; print ( "count" )复制代码
We use \
for line breaks
print \ ("Runsen")复制代码
White spaces are very important in python, lines The leading blank space is the most important, also known as indentation. The blank space at the beginning of the line (spaces and tabs) is used to determine the indentation level of the logical line and thus the statement.
Operator | Name | Example |
---|---|---|
Add two objects | Addition, such as 3 5 gets 8, characters can also be added 'a' 'b' gets 'ab' | |
- | One number minus another number | 5 - 2 gets 3 |
* | Multiplication Multiply two numbers or return a string that is repeated several times | 2 * 3 gets 6,'a' * 3 Get 'aaa' |
** | power Return x raised to the y power | 3 ** 4 get 81 (ie 3 * 3 * 3 * 3) |
/ | divide x by y | 4/3 to get 1 (division of integers yields an integer result). 4.0/3 or 4/3.0 gets 1.3333 |
// | Take integer division and return the integer part of the quotient | 4 // 3.0 gets 1. |
% | Modulo Returns the remainder of division | 8%3 gets 2. -25.5%2.25 gets 1.5 |
Shift left, shift the binary system of a number to the left by a certain amount, that is, add as many 0s to the right, | For example, 2 << 2 gets 8, and binary 10 becomes 1000 | |
Shift the bits of a number right Shift a certain number to the right, that is, delete the digits on the right | 10>>2 to get 2, binary 1010 becomes 10, directly delete the next 2 digits | |
Bitwise AND | Bitwise AND of 9 & 13 gets 9, binary 1001&1101, becomes 1001, the corresponding positions of both values are 1, then the result is 1, Otherwise, it is 0 | |
bitwise or | bitwise or 5 | 3 to get 7. Binary 101&11 becomes 111. If one of the corresponding positions of the two values is 1, then the result is 1, that is, if both are 0, the result is 0. 101 and 11 are not both 0, so 111 | |
Bitwise XOR | Bitwise XOR of numbers 5 ^ 3 gets 6, binary 101&11, becomes 110, the two values correspond The positions are the same, then the result is 0, that is, if they are all 0 or both 1, the results are 0, 101 and 11, the first one is 1, so 110 | |
Bitwise flip | The bitwise flip of x is -(x 1) ~5 gets 6 | |
Less than returns whether x is less than y. | All comparison operators return 1 for true and 0 for false. 5 < 3 returns 0 (i.e. False) and 3 < 5 returns 1 (i.e. True). It can also be connected arbitrarily: 3 < 5 < 7 returns True. | |
Greater than Returns whether x is greater than y | 5 > 3 returns True. If both operands need to be numbers | |
less than or equal to, return whether x is less than or equal to y | x = 3; y = 6; x <= y returns True | ##>= |
!= | Not equal to Compare whether two objects are equal | |
not | Boolean "not" If x is True, returns False | |
or | Boolean "or" If x is True, it returns True, otherwise it returns the calculated value of y. | |
##2.2 Operator precedence | .Operator precedence (low to high) | |
Operator | Description |
Boolean "or" | |
---|---|
not x | |
in, not in | |
is,is not | |
##<,<=,>,> =,!=,== | |
` | ##`|
^ | Bitwise XOR |
` | ` |
##& | Bitwise AND |
<<,>> | Shift |
Addition and Subtraction | |
Multiplication, division and remainder | |
Positive and negative signs | |
Bitwise flip | |
Index | |
Bitwise flip | |
Attribute reference | |
Subscript | |
Addressing segment | |
Function call | |
Binding or tuple Display | |
List display | ##{key:datum,...} |
'expression,...' | |
The above is the detailed content of The first Python knowledge points compiled for beginners. For more information, please follow other related articles on the PHP Chinese website!