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

Python teaching notes summary

編輯:Python

Python Basic knowledge of 1

  • Variable

1. A variable is a storage space with a name

2. Variable name ( Or function name ) Naming rules :

A. Variable names can only be made of letters 、 Numbers 、 Underline composition

B. Variable names can only start with letters or underscores ( Cannot start with a number )

C. The variable name cannot be the same as the keyword in the system

D. Variable names are case sensitive

E. Variables are defined before they are used

3. Assignment symbol :a=b  ——>     take b The value of is assigned to a( The right value d To the variable on the left )

4.Python Medium 33 Key words :

True      None     True      class     continue        def         finally           for         from

nonlocal       lambda         is           return    try          while     and        as

assert    del         elif         else       global    if       import   not         or    pass

with       yield      break     except   in    rais

  • Basic statement
  1. for sentence

How to write it :     for i in range(num):

                  The loop body

  1. num Is a number ;range Function generates a sequence , The generated sequence is 0-(num-1) common num Number
  2. The execution process is :i Assign the number generated by the sequence in turn , The loop body is executed once without any assignment
  1. while sentence

How to write it :       while( Conditions ):

                  The loop body

  1. A condition can be a variable or an expression
  2. The execution process is : When the conditions are met , Just execute the contents of the loop body , Jump out of the loop when the condition is not satisfied
  1. if sentence

How to write it :     if( Conditions ):

                  Execution event

  1. A condition can be a variable or an expression
  2. The execution process is : When the conditions are met , To execute the corresponding required execution event
  1. if...else sentence

How to write it :     if( Conditions ):

                  Execution event 1

               else:

                  Execution event 2

  1. A condition can be a variable or an expression
  2. The execution process is : When the conditions are met , Execute the required execution event 1, Otherwise, execute the required execution event 2;

《 Add 》:random Random function

                     Format :random(a,b)——> stay a To b Between random numbers , The range of generated numbers is a—(b-1), That is, the minimum is a, The maximum is b-1

  • Operator
  1. Logical operators (and、or、not)

A.a and b  ——>      And operation ,a And b Logical values are all true , The result is true , Otherwise, the result is false

B.a or b    ——>      Or operations ,a And b One of the logical values is true , That's true , Otherwise, the result is false

C.not a     ——>      Reverse operation , Yes a The logical negation of ,a Is true and false after operation , On the contrary, it is true

  1. Comparison operator (>、<、==)

A.a>b   ——>     Greater than operator ,a Greater than b The result is true , conversely ,a Less than b The result is false

B.a<b   ——>     Less than operator ,a Less than b The result is true , conversely ,a Greater than b The result is false

C.a==b ——>     Equals operator ,a be equal to b The result is true , conversely ,a It's not equal to b The result is false

3 . Mathematical operators (+、-、*、/、%)

  1. c=a+b ——>        The addition operator , take a+b The value after the operation is assigned to c Variable
  2. c=a-b ——>         Subtraction operators , take a-b The value after the operation is assigned to c Variable
  3. c=a*b ——>         Multiplication operators , take a*b The value after the operation is assigned to c Variable
  4. c=a/b ——>         Division operator , take a/b The value after the operation is assigned to c Variable
  5. c=a%b ——>         The remainder operator , take a%b The value after the operation is assigned to c Variable ( seek a/b The remainder of )
  • list
  1. List creation

Format : List name =[“ value 1”, “ value 2”, “ value 3”, “ value 4”, “ value 5”, “ value 6”]

  1. The naming rules for list names and variable names are the same
  2. The data value types in the list can be mixed
  1. Index of list and extraction of values

Indexes ——> Describes the number of element values in the list , Index from 0 Numbered starting

Extraction of values ——> List name [ Indexes ], The list name plus the corresponding position index of the extracted elements in the list , This value can be extracted and used

  1. Replacement of list elements ( change )

Format : List name [ Indexes ]= Changed value ——> Assign the value to be changed to the corresponding position in the list

  1. The list element is empty

Format : List name .clear()——> After performing this operation , All values in the list will be cleared

  1. Insert elements... Into the list

Format : List name .insert( Location , Elements )——> Insert the element in the specified position in the list

  1. List length ( Element number ) Calculation

Format :len( List name )——> After performing this operation , You can get the number of elements in the list ( length )

  1. Determine if the element is in the list

Format : Specify elements in List name ——> Determine whether the specified element is in the list , If yes, the return value is true , Otherwise, the return value is false

  1. Deletes the specified element from the list

Format : List name .pop( Indexes )——> After performing this operation , The index value at the corresponding position in the list will be deleted

  • Need familiar words

if     else        while      range( Sequence functions )       random( Random function )         and        or   

not         clear( clear list )     insert( List element insert )       len( List length calculation )  

in    pop( The list specifies that the element is deleted )        True       False


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