程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python learning (1) - Basic Syntax (data types and operations)

編輯:Python

1 data type

2 Output and input

2.1 Output


2.2 Input

3 Data type conversion


4 Operator

+ - * /
// to be divisible by ( Seeking quotient )
% Take the remainder
** Index , Power operation
() You can change the priority

4.1 ⽐ Comparison operator

⽐ The result of the comparison operator is bool type , namely True, Or is it False.

== Judge whether it is equal , Equality is True. Inequality is False
!= Judge whether it is not equal , Inequality is True, equal False
><>=<=

4.2 Logical operators

Logical operators can connect multiple expressions , The common result of the two expressions determines that the final result is True, still False.

and Logic and , Both conditions of connection must be True, The result is
True, ⼀ False is false
If the first ⼀ The first condition is False, Will not judge the ⼆ Conditions
or Logic or , Both conditions of the connection are False, The result is
False, ⼀ It's true
If the first ⼀ The first condition is True, The first ⼆ One condition will no longer be judged
not Logic ⾮, Take the opposite , Turned out to be True, Turn into False, Turned out to be
False, Turn into True

5 if Judgment statement

5.1 if

if Judge the condition :
The judgment condition is True, Can hold ⾏ Code for
The judgment condition is True, Can hold ⾏ Code for
...
Code written in the top pane , For and on behalf of if Judgment doesn't matter
stay python Chinese envoy ⽤ Indent , Instead of code hierarchy , stay if sentence
Within the indent of , Belong to if Code block of statement ( many ⾏ The code means )

5.2 if else

if Judge the condition :
The judgment condition is True, Can hold ⾏ Code for
The judgment condition is True, Can hold ⾏ Code for
else:
The judgment condition is False, Can hold ⾏ Code for
The judgment condition is False, Can hold ⾏ Code for

5.3 if elif

if Judge the condition 1:
Judge the condition 1 become ⽴, Of board ⾏ Code for
elif Judge the condition 2:
Judge the condition 1 no ⽴, Judge the condition 2 become ⽴, Can hold ⾏ Code for
else:
Judge the condition 1 And judging conditions 2 Not even ⽴, Of board ⾏ Code for

6 3、 ... and ⽬ operation

 Variable = expression 1 if Judge the condition else expression 2

7 loop

7.1 while loop

while Judge the condition :
Judgment condition ⽴, Of board ⾏ Code for
Judgment condition ⽴, Of board ⾏ Code for

7.2 for Loop traversal

for Variable in character string :
Code

Python Look at the scope of the code by indentation .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved