PythonProgramEverything used is called an object. For every number, string, or even function as an object, python is an extremely completely forward object.
#! Learn more
I = 5
Print I
I = I + 1
S = ''' this is a multi-line string.
This is the second line .'''
Print s
G = 'chine \
Chekc'
Print g
Note:
1. # Annotation
2. The start of each line cannot be empty or tab
3. When using variables, you only need to assign them a value. No need to declare or define data types
How to indent
Do not mix tabs and spaces to indent, because it cannot work normally when crossing different platforms. We strongly recommend that you use a single tab or two or four spaces at each indentation level. Select one of the three indent styles. More importantly, select a style and use it consistently, that is, only this style is used.
OPERATOR:
operator Name Description Example
+ Add two objects and add 3 + 5 to get 8. 'A' + 'B' get 'AB '.
-minus to get a negative number or one number minus another-5.2 to get a negative number. 50-24 get 26.
* multiply by two numbers or return a string that is repeated several times. 2*3 gets 6. 'La '* 3 to get 'lala '.
** power Returns X's Y Power 3 ** 4 to get 81 (3*3*3*3*3)
/divide X by Y4/3 to get 1 (the Division of integers returns an integer ). 4.0/3 or 4/3. 0 to 1.3333333333333333
// get the entire Division . Return the integer part of the quotient. 4 // 3.0. The value is 1.0.
% modulo return the remainder of Division 8% 3 to get 2. -25.5% 2.25 get 1.5
shift right to shift a certain number of BITs to the right. 11> 1 to get 5. -- 11 is expressed as 1011 in bits. After moving 1 bit to the right, 101 is obtained, that is, 5 in decimal format.
& bitwise AND number, and 5 & 3 get 1.
| bitwise OR 5 | 3 returns 7.
^ bitwise OR 5 ^ 3 get 6
~ The bitwise flip of X is-(x + 1 )~ 5.
whether X is greater than Y 5> 3. True is returned. If both operands are numbers, they are first converted to a common type. Otherwise, it always returns false.
<= returns whether X is less than or equal to Y x = 3; y = 6; x <= y returns true.
= whether return X is greater than or equal to Y x = 4; y = 3; x> = y returns true.
= equals to whether the comparison object is equal x = 2; y = 2; X = y returns true. X = 'str'; y = 'str'; X = Y, false is returned. X = 'str'; y = 'str'; X = y returns true.
! = Not equal to whether two objects are not equal x = 2; y = 3; X! = Y returns true.
Not Boolean "Non". If X is true, false is returned. Returns true if X is false. X = true; not y returns false.
And Boolean "returns false if X is false, X and Y; otherwise, it returns the calculated value of Y. X = false; y = true; X and Y, returns false because X is false. Python does not calculate y here, because it knows that the value of this expression must be false (because X is false ). This phenomenon is called short circuit computation.
Or Boolean "or" If X is true, it returns true; otherwise, it returns the calculated value of Y. X = true; y = false; X or Y returns true. Short circuit calculation is also applicable here.
Operator priority:
Operator description
Lambda expressions
Or Boolean "or"
And Boolean "and"
Not x Boolean "Non"
In, not in member Testing
Is, is not identity test
<, <=,>,
>= ,! =, = Comparison
| By bit or
^ Bitwise OR
& Bitwise AND
<,> Shift
+,-Addition and subtraction
*,/, % Multiplication, division, and fetch
Yu
+ X,-x plus and minus signs
~ X flip by bit
** Index
X. Attribute attribute reference
X [Index] subscript
X [index: Index] addressing segment
F (arguments...) function call
(Experession,...) bind or display tuples
[Expression,...] list display
{Key: datum,...} dictionary display
'Expression,... 'String Conversion
Routine:
#! Learn morelength = 5 breadth = 2; Area = length * breadthPrint'Area is ', area,' \ n', 'Perimeter is ', 2 * (Length + breadth)
Output:
Area is 10
Perimeter is 14
Note: although no space is added, python is automatically added during output.