establish new project The compiler needs to be configured (interpreter) by python Or others , Specific for previously configured interpreter Medium system interpreter.
Main points two
If there is no need , Do not use virtualized environments .
Main points three
newly build file when , choice python file.
Point four
newly build project when , If there is not closed project, choice This Window Overwrite original project ,New Window Create another window .
Point five
Two 、pycharm Personalized configuration
File/Settting/Editor/File and Code Templates Choose from Python Script Configuration content in , Including author 、 Time and so on , Example
File/Settting/Editor/Color Scheme/General Choose from Scheme Configure themes in .
File/Settting/Editor/Font Configure fonts in .
3、 ... and 、 Basic grammar
1. notes
1.1 - Comments are the parts of the code that do not participate in compilation and execution ,( The comment section does not affect the program operation )
Single-line comments ( Add... Before comments #)– Shortcut key ctrl+/ Quickly add a single line comment .
Multiline comment ( Add... At the beginning and end of the comment """ or ‘’‘)
1.2 - Use of notes
Explain the code , Improve code readability
Cancel code function
2. That's ok
python One line of code , The end cannot be written with a semicolon .
You can add semicolons between statements (;) Implement two statements on one line .
3. Indent
The space before a statement is called indentation .
You can't add spaces before a statement .
4. Identifiers and keywords
Identifiers are made up of letters 、 Numbers or underscores make up , And can't start with a number .
The reserved character is python An identifier that has a special function or meaning .
5. Common data and data types
5.1 Digital data
Data used to represent the size of a number .
The representation method in the program is similar to that in mathematics , And support scientific counting (aeb, namely a*10^b)
The corresponding data type is integer (int) And floating point (float)
5.2 Text data
str class , It is used to represent the data corresponding to text information .
5.3 Boolean data
bool class , The two results are True and False, They correspond to each other 0 and 1.
Representation : direct writing True、Flase.
5.4 Null value
None、 empty ([]、{}、()、0)
6. Type operation
Get data type :type( data ) - Get the specified data type
Type conversion : Type name ( data ) - Converts the specified data to the specified type
Conversion rules :
int Can be converted into float( Add decimal places )、str、bool( Not 0 Are all True)
float Can be converted to int( Remove decimal places )、str、bool( Not 0.0 Are all True)
str Can be converted into int( Integer type text )、float( Numeric text )、bool( All contents are True)
bool Can be converted into int(True by 1,False by 0)、float(True by 1.0,False by 0.0)、str(‘True’、‘False’)
Other data are transferred to bool
All types of data can be transferred to bool, All zero and null values are False, Others are True
Other data are transferred to str
All types of data can be converted to str, Put quotation marks directly
float and int Oneness and mutual transformation
Digital class str Can be converted to float、 Integer class str Can be converted into int
7. Output function -print
7.1 print usage
print Is to print out the data in the program in the console . What is displayed in the console , It must be used in the program print Print out the
One print Print multiple data at the same time :print( data 1, data 2, data 3,…)
7.2 Advanced usage
customized end
By default, a print The printed content occupies one line
Printing principle : Procedure in progress print During operation , Will print the data first , The data will be printed after printing end Value ( Default newline )
customized sep
Printing principle : Procedure in progress print During operation , Will insert... Between multiple data sep Value ( Default space )
‘\n’ Newline character
8. Input function -input
Variable =input( Enter the prompt message ) - Prompt the user to enter content , And save the input to the variable .
5、 ... and 、 Homework
choice question
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
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
Next ⾯ Which is not Python Legal identifier (B) A. int64 B. 40XL C. self D. stu_name
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
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
Python The symbol for a single line note in is ( # ), many ⾏ The symbol of the note is ( ‘’‘ or “”“ ).
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 ).
Python The program file extension is ( .py ).
stay Python in ,int The data type represented is ( Integers ).
stay Python in , String data needs ⽤( “” ) or ( ‘’ ) The parcel .
stay Python in , Boolean types have ( 2 ) It's worth , Namely ( True、False ).
If you want to see ⼀ The data type of a data or variable , It can be used ( type) function .
Programming questions
Write program tips ⽤ User input ⽤ Account name and password , And will lose ⼊ The contents of are saved to different variables .
acount=input(' Please enter a user name ')
password=input(' Please input a password ')
send ⽤ One print Output 3 Data ,3 There's data in ⼀ Row display , And use the equal sign (=) separate .
print(1,2,3,sep="=")
Short answer
When declaring variables , What are the precautions for variable names ?
Identifiers are made up of letters 、 Numbers or underscores make up , And can't start with a number .
It can't be Python Key words of
Case sensitive
Please write out Python What are the advantages of language .
Simple and clear
Open source 、 Portability 、 Embeddable and extensible 、 Strong ecosystem, etc .
Please write out Python often ⻅ Application fields of .
Web The backend development 、 Network data collection ( Reptiles )、 Artificial intelligence 、 Automatic operation and maintenance 、 automated testing 、 Quantitative trading 、 Scientific calculation and data analysis .
Write down the questions you have about today's lecture ( Or knowledge points that feel difficult ).