Basic usage of pycharm, Python annotation syntax, variables, constants, garbage collection mechanism, data types

1. Note the file path

 

 

 

 

 

 

 

 

  I put the files on disk D, as shown below; You can set it according to your own situation

 

 

  2. The python environment should be downloaded locally

As shown below:

Click the existing environment of the machine. If NO interpr is prompted, click step 2

 

 

 

 

 

 

 

 

 

  If not, continue as shown in the figure below

 

 

 

 

 

 

Topic selection

 

 

Click file, settings, - Editor - color - scheme    

As shown in the figure below:

 

 

 

 

 

 

 

 

 

  pycharm switch interpreter

Click file settings Project Python Interpreter

As shown in the figure below:

 

 

 

 

 

 

 

 

 

 

 

How to create a python script file

Because the suffix of the file is used to identify the internal data characteristics of the file, our python file also has a unique suffix   . py

 

 

 

 

 

 

 

 

 

 

 

  How to adjust font size

Open file---settings---Editor---general --- and check change font size with ctrl mouse wheel

 

 

  How to run py files

Right click in the file content area and select run.... py

 

 

 

 

Annotation syntax of python

 

"" "comments are the mother of code!!!" "" 1. What are comments? Comments are the interpretation of a piece of code. They do not participate in the operation of the program, but only serve as a reminder. "

2. How to use annotation method 1 use alarm # single line annotation method 2 use three quotation marks (single and double) multi line annotation

3.pycharm annotation shortcut key ctrl +?

"" "1. There must be a space between the alarm number and the comment text."

2. If a single line comment follows a line of code, you need to leave two blank before writing. pycharm also provides the function of automatic format code ctrl+alt+l code reformat code ""“

python code writing specification > > >: pep8 specification # how to quickly master the automatic prompt with the help of pycharm, compare it before and after, and memorize it every day

 

variable

variable

### # 1. What are variables
	That is, the amount of change is used to record a certain state of things(Ability to imitate human memory)
	
### # 2. How to use variables
	In daily life:
        full name:Jason 
        Age:18
        hobby:study
	In the program:
        username = 'jason'
        age = 18
        hobby = 'music'
  
"""
Syntax format
	username = 'jason'
	Variable name assignment symbol variable value

Underlying principle(Will!!!)
	In case of assignment symbol, first look at the one on the right and then the one on the left
		age = 18
			1.Apply for a memory space storage 18 in the memory space
			2.Bind the memory space address of 18 to the variable name age
			3.Then, if you want to access 18, you can use the variable name age Just visit

 

 

Naming conventions and styles

# Naming conventions
	1.Variable names can only be any combination of numbers, letters and underscores
    	user@name(incorrect),_(sure),pwd_123_aaa(sure)
    2.Variable names cannot start with numbers. It is recommended not to start with underscores because they have special meanings
    3.Variable names cannot conflict with keywords
    4.Variable names must be named according to the name(important)
    	'''Variable name is the core, no matter how long the variable is'''
# Naming style
	1.Hump body  
    	Big hump  # All words are capitalized
        	UserNameFromDb
        Small hump  # The first letter is lowercase and the rest is uppercase
        	userNameFromDB
        """JavaScript Hump body is recommended"""
    2.Underline  # Words are separated by underscores
    	user_name_from_db 
        """python Underline is recommended"""

constant

It is mainly used to record some unchanged states

stay python There is no constant in the real sense. We regard all uppercase variables as constants
	HOST = '127.0.0.1'  # Generally, it is used more in the configuration file
 In other programming languages, there are constants in the real sense, which cannot be modified once they are defined
	const pi = 3.14  # Define constants
    pi = 4  # Modification is not supported

Three elements of variables

1. Value of variable
2. Memory address of variable
3. Data type of variable

Examples

name = 'jason'
print(name) # value

 

 

 

  print(id(name)) # a string of numbers is equivalent to the memory address number

 

 

  print(type(name)) # data type < class' STR '>

 

 

python underlying optimization

When the amount of value data is very small, if multiple variable names need to be used, they will point to the same block of address

A variable name can only point to one memory address

 

  A memory address can have multiple variable names pointing to

 

 

Garbage collection mechanism

Definition of garbage data: as shown in the figure below, see

A set of automatic recycling scheme for garbage data python is developed
1. Reference count
There are several variable names on the variable value in memory, and the binding reference count is just a few. As long as it is not 0, it is not garbage

For example, two variables x = 10 and y = 20 are explained in detail as shown in the figure below,

 

  When we execute x=y, the stack area and heap area in memory change as follows

 

 

2. Mark clearing --- when the memory is about to be full, python will automatically pause the execution of the program and scan the data in the memory from beginning to end

After marking, the marked data is cleared at one time

 

 

3. Generation by generation recycling - the supervision of data will be divided into three levels, and the frequency of supervision will decrease as the level decreases

 

 

 

data type

# What is a data type?
	In real life, there are many ways and manifestations of storing data
    	Text file table file video file audio file picture file...
    stay IT The storage methods and forms of data in the world are also changeable
    

Integer int of data type

# Understanding of Vernacular: integer int
 effect:Record the age of the person and the number of classes ...
definition:
    	age = 18  # Writing an integer directly is an integer


 

 

Floating point float of data type

# Understanding of Vernacular: decimal float
 effect:Record the person's weight, salary and height
 definition:        
    salary = 3.1  # Writing decimals directly is floating point

 

 

Small summary

Integer and floating point types can be collectively referred to as numeric types 
	It is mainly used for mathematical operation and comparison operation

Keywords: Python

Added by jurasiprize on Tue, 02 Nov 2021 12:58:17 +0200