Table of contents
1. Build Python development environment
1.2 PyCharm download and installation
2. Classification of annotations
1. Build Python development environment
1.1 Python interpreter
①The role of python: similar to Javac in Java
② Types of interpreters:
--CPython: Interpreter developed in C language (official)
--IPython: An interactive interpreter based on CPython
--Other interpreters: PyPy: An interpreter developed based on the Python language
Jython: An interpreter based on the Java language platform, which directly compiles Python code into Java bytecode execution
IronPython: A Python interpreter running on a Microsoft platform that can directly compile Python code into .Net bytecode
1.2 PyCharm download and installation
This article has detailed steps: https://blog.csdn.net/qq_50598558/article/details/115611398
1.3 Use of PyCharm
① Note that the new project is: select the version of the Python interpreter, use the one downloaded by yourself, do not use the default virtual one
②Modify the interface font and the font of the editor interface, as shown below:
--Interface font:
--Editor interface font:
2. Classification of annotations
2.1 Single-line annotations
①Only one line can be commented
②Format: # Comment content
③Shortcut key: Ctrl+/2.2 Multi-line comments (block comments)
①Multiple lines of content can be commented, generally used in the case of commenting a piece of code
②Format 1: 6 double quotes
"""
First line comment,
second line comment,
third line comment
"""
③Format 2: 6 single quotes
'''
Comment on the first line,
comment on the second line,
comment on the third line
'''
3. Define variables
3.1 Grammar
①Variable name = variable value
②The variable name must conform to the identifier naming rules3.2 Logo naming convention
① Composed of numbers, letters, and underscores
② Cannot begin with a number
③ Cannot use built-in keywords④Strictly case-sensitive
3.3 Naming conventions
①See the name and know the meaning
②Hump nomenclature
--Big hump: that is, the first letter of each word is capitalized
--Small hump: The first letter of the word after the second (including) is capitalized
③Underline
4. Data type
①Value: int (integer type), float (floating point type) are equivalent to int and double in Java
②bool (Boolean): True (true), False (false) is equivalent to boolean in Java
③ str (string) is equivalent to String in Java
④list (list): variable length, subscript, and variable elements are equivalent to the list in Java
-- Format: [element 1, element 2, ...]
--list built-in method:
--python subscript:
⑤tuple (tuple): the length is immutable, subscripted, and the elements are immutable, which is equivalent to the array in Java
-- format: (element1, element2, ...)
--Note: How to quickly assign the data in the tuple to multiple variables
Mode 1: variable 1, variable 2 = tuple name
Mode 2: variable 1, *variable 2 = tuple name⑥set (collection): no subscript, no repetition, equivalent to set in Java
-- format: {element1, element2, ...}
--Read elements: pop (no subscript, random read)
--Remove element: remove(element name)
⑦dict (dictionary) is equivalent to map in Java
--Format: {"key":"value", "key":"value",...}
--Note: All the keys here need to add "", and if the value is a value, you don't need to add ""
Validate the data type of the variable:
type (data)
Data type conversion:
int(x): converts X to an integer
float(x): converts X to a floating point number
str(x): converts the object X to a string
tuple(s): converts the sequence S to a tuple
list( s): convert the sequence S into a list
eval(str): convert the string into the corresponding data type
5. Escape characters
① Newline: \n
② Tab: \t
③ End character: print("content", end="\n")
6. Formatted output
6.1 Splice+
print("variable name: "+variable)
variable must be a string type6.2 Splicing characters,
print("Variable name: ", variable)
6.3 Formatting symbols
①%s: string
②%d: signed decimal integer
--%0nd: complete with 0 in front
--%03d: replace less than three digits with zero
③%f: floating point number
--%.nf: keep decimals Number of digits
--%.2f: keep two decimal places
④Format and output multiple variables
--Syntax: % (variable 1, variable 2)
7. Console input
Syntax: variable = input("prompt information")
Note: The variable type obtained here must be str
That's all for today's learning record, bye!
Description: Learning records, if there are mistakes, please correct me, if you have any questions, welcome to comment