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

day2_ Python Programming ⼊ door summary and operation

編輯:Python

Today's summary

One 、 Common shortcut key

ctrl + c - Copy / Copy

ctrl + v - Paste

ctrl + / - Add or remove comments

ctrl + x - shear

ctrl + s - preservation

ctrl + z - revoke

ctrl + a - Future generations

Two 、 Basic grammar

1、 notes : Is the part of the code that does not participate in compilation and execution ( The existence of comments will not affect the function of the program )

Single-line comments : Add... Before the notes # ( Shortcut key : ctr + /)

# I'm a line of comments 

Multiline comment : Put multiple lines of comment in three quotation marks ( Three double quotes or three single quotes are OK )

""" I am the first 1 Line notes I am the first 2 Line notes I am the first 3 Line notes """

The function of annotation :

a. Annotate the code with , Improve the readability of the code

b. Cancel code function

2、 Lines and indents
1) That's ok
python One line of code , You can end a line without a semicolon , If you have to display multiple statements on one line ,

A semicolon must be added between statements

2) Indent : The space before a statement is called indentation

A statement cannot be preceded by any blank space

3、 Identifiers and keywords

1) identifier - Naming requirements

python Identifier requirements : By letter 、 Numbers or underscores , And numbers don't start

2) keyword - python Some identifiers with special functions or special meanings in , It can't be used for other purposes !

False None True and as assert break class continue def del elif else except

finally for from global if import in is lambda nonlocal not or pass raise

return try while with yield

4、 Common data and data types

1) Digital data : Data used to represent the size of a numeric value , for example : The age of people 、 height

​ The method of representing digital data in a program : The same way that numbers are represented in Mathematics , And support scientific counting

​ The type corresponding to the number : Digital data is divided into integer types (int- Integers ) And floating point (float- decimal ) Two kinds of

2) Text data : It is used to represent the data corresponding to text information , for example : full name 、 Address

​ Representation : The text data must be enclosed in double or single quotation marks ,

​ type : character string (str)

3) Boolean data : Only True and False Two values ,True Said really 、 sure ;False Said the false 、 no .

​ (True and False Is the key word )

​ Representation : direct writing True、False

​ type : Boolean (bool)

4) Null value :None (None Is the key word )

​ type :NoneType

5、 Type operation

1) Get data type :type( data ) - Gets the type of the specified data

type(' Hello ')

2) Type conversion : Type name ( data ) - Converts the specified data to the specified type

print(int(3.5))

3、 ... and 、 Output function

1、print Is to display the data in the program on the console ( Print ) come out . What is displayed in the console , It must be used in the program

print Printed content

1) Basic usage

a. One print Print a data :print( data )

print('hello')

b. One print Print multiple data at the same time :print( data 1, data 2, data 3, …)

print(10, 20)

2) Advanced usage

a. customized end: print( data 1, data 2,…, end= character string )

By default, there is one print The printed content occupies one line

Printing principle : Program designation print During operation , Will print the data first , The data will be printed after printing end Value (end The default value of is

Line break )

b. customized sep

customized sep It is used to control when printing data at the same time , How data is separated from data , Default is space

Four 、 Input function

1、input function
Variable = input( Enter the prompt message ) - Prompt the user to enter content , And save the input to the variable

age = input(' Please enter your age :')

day2 Python Introduction to programming

choice question

  1. Which of the following statements is in Python It's illegal ?(B)
    A. x = y = z = 1
    B. x = (y = z + 1)
    C. x, y = y, x
    D. x = y
  2. About Python Variable , The following statements are wrong (C)
    A. Variables don't need to be typed
    B. Variables can be reassigned
    C. Variable ⽆ You must first create and assign ⽽ Direct use ⽤
    D. The same variable can hold different types of values
  3. Next ⾯ Which is not Python Legal identifier (B)
    A. int64
    B. 40XL
    C. self
    D. stu_name
  4. The following about Python language ⾔ It's wrong to say (C)
    A. Python It's interpreted language
    B. Python yes ⾯ Speak to the object ⾔
    C. Python2.x and Python3.x Is fully compatible
    D. ordinary ⽂ This editor can also write Python Program
  5. The following about print Function usage is wrong (D)
    A. print(100)
    B. print(100, 200)
    C. print(100, ‘hello world!’)
    D. print(10 20)

Completion

  1. Python The symbol for a single line note in is ( # ), many ⾏ The symbol of the note is ( ‘’’ ‘’’ perhaps “”“ ”“” ).
  2. sentence a, b=10,20 Of board ⾏ after ,a The value of is ( 10); sentence a, a = 10, 20 Of board ⾏ after ,a The value of is ( 20 ).
  3. Python The program file extension is ( .py ).
  4. stay Python in ,int The data type represented is ( integer ).
  5. stay Python in , String data needs ⽤( Single quotation marks ) or ( Double quotes ) The parcel .
  6. stay Python in , Boolean types have ( 2 ) It's worth , Namely (Ture and Flase ).
  7. If you want to see ⼀ The data type of a data or variable , It can be used ( type ) function .

Programming questions

  1. Write program tips ⽤ User input ⽤ Account name and password , And will lose ⼊ The contents of are saved to different variables .

    username = input(' Please enter a user name :')
    password = input(' Please input a password :')
    
  2. send ⽤ One print Output 3 Data ,3 There's data in ⼀ Row display , And use the equal sign (=) separate .

    print('10 + 5',20,'hello word',sep='=')
    

Short answer

  1. When declaring variables , What are the precautions for variable names ?

    a. Is an identifier.

    b. It can't be a keyword

    c. Know what you know ( When you see the variable name, you know what data is stored in the variable )

    d. Do not use the system function name 、 Class name and module name

    e. The letters are all lowercase

    f. Multiple words are separated by underscores

  2. Please write out Python What are the advantages of language .

    Grammar is simple , The cost of learning is low , There are many standard libraries and third libraries , Powerful , Open source code .

  3. Please write out Python often ⻅ Application fields of .

    Data analysis 、 Artificial intelligence 、 data mining 、 Reptiles 、 The front-end development .

  4. Write down the questions you have about today's lecture ( Or knowledge points that feel difficult ).

    nothing


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