Article From:https://www.cnblogs.com/xiaohuatongxue/p/9970562.html

<<Python Foundation & gt; & gt;
brief introduction
pythonThe birth of
  Founder: Guido van Rossum (Dutch)
  Time: 1989
pythonLanguage applications:
  System operation and maintenance
  Network programming (search engine, crawler, server programming)
  Scientific calculation
  Artificial Intelligence, Robot
  web Development
  cloud computing
  Big data and database programming
  education
  Game, Image Processing
  Others uuuuuuuuuuuu

Advantages and disadvantages:
  Advantage:
    Object Oriented (Java, C++, Python, C#, Swift)
  Free Admission
  Portability (Windows, Linux, Unix, IOS, Android)
  Mixed Programming (C/C++/Java/net)
  Easy to learn and easy to use
  Wide range of applications
  Open Source
Disadvantages:
    Compared with C/C++, the execution speed is not fast enough.
    Can’t close source code

pythonOfficial website
  https://www.python.org

pythonVersion
  python V2.7(2020Year-end maintenance)
python V3.5(Current teaching)
python V3.8(Latest)

pythonOperation:
  pythonExplain the type of executor
    CPython    (CLanguage development)
    JPython    (JavaLanguage development)
    IronPython (.netDevelopment)
    PyPy (PythonLanguage development)

The first Python program
  Writing: hello. PY

Execute Python program
  $ python3 File path name.py
Example:
  $       

Commonly used file suffixes:
    .py            pythonSuffix
    .c            cLinguistic suffix
    .cpp/.cc/.cxx  C++Linguistic suffix
    .java          JavaLinguistic suffix

Write and execute code in Python interactive mode
  Enter Interactive Mode
    $ python3 <Carriage return >
  Exit interactive mode:
    >>> quit() <Carriage return >
>>> exit() <Carriage return >
Or enter: Ctrl + D (input file terminator)

python Notes
  Start with # until the end of the line
  Effect:
    Leave the content of the comment out of execution
  sublime Note shortcut key Ctrl +/

pythonComposition of the procedure:
The program consists of modules.
Modules are composed of data, functions, classes, etc.
Functions consist of statements
Statements consist of expressions

python Core data types
  Numbers (integer int, float, complex, bool)
  String str, list, etc.

Integer int
  Integers are numbers without decimal parts

  The literal representation of integers
    Decimal representation
      Such as:
        10
200
-100
Octal representation
  Such as:
    0o177(127)
0o11(9)
Hexadecimal representation
  Such as:
    0x11 (17)
0xFF (255)
0x1a2b
Binary representation
  Such as:
    0b111
0b101
Floating point type float
Floating-point numbers are numbers with decimal parts (decimal parts can be 0)
The literal representation of floating-point numbers:
  Decimal representation:
    Such as:
      3.14 3.1 3.0 0.14 .14
 Scientific counting method
   Such as:
     Decimal e/E (Positive and Negative) Index
   Such as:
     6.18E-1 (Equivalent to 0.618)
2.9979E8 (Equivalent to 299790000.0)
Complex type complex
It is divided into two parts:
Real part (real)
Imaginary part (image)
The imaginary part is the number ending with J or J.

Literal value:
  1j
(2J)
1+2j
3-4j

Boolean type number bool
Numbers used to represent truth and falsehood
  True Represent truth (condition satisfied or established)
    False Express false (condition is not satisfied or not valid)
  Explain:
    True The value is 1.
    False The value is 0.

Built-in object
  Null value None
None Is a special object that represents nonexistence
Effect:
  Used for occupying
  Variable solution

Expressions and Operators
Expressions
Consisting of a number or number, an operator, etc.
Effect:
  Usually let the computer do something and return the result.
Such as:
  1 + 2
1 +2 * 3 + 4 / 5
Operator:
  Arithmetic operators:
    + addition
    - subtraction
    * multiplication
    / division
    // Floordiv removal from floor
% Seek surplus
** exponentiation
/ division
  Dividing results in floating-point numbers that do not discard decimal parts.
  1/3 # 0.33333333
8/2 # Get 4

// Floor removal
   The result of division is to remove the decimal part and take it downward.
   Such as:
   7/3 # 2.33333333
7//3 # Get 2
3.25//1.5 # Get 2
% Seek surplus
  Such as:
    7%3 # Get 1
3.25%1.5 # Get 0.25
** exponentiation
   Format:
     x**y
  Y th power which means x
Such as:
  4**2 # Get 16
3**4.0 #Get 81

Practice:
   1. A shop sells watermelons for 7 yuan each. How many watermelons can you buy with 20 yuan? How much is left?
   2.A student’s graduation salary is 10,000 yuan, which is increased by 20% every year. What’s the salary of this student ten years later?
   Answer:
      1. 1) 20//7 # Buy two watermelons
           2) 20%7 # 6 yuan left.
      2. 10000*(1+0.2)**10

Operator precedence
   **
* / // %
+ –
Example:
1+3*3**2+4//2

Parentheses grouped subexpressions
  ()The internal expression is computed first
Hybrid type automatic upgrade
  1+ 2.14 The return type is floating-point 3.14
3+4.0 Return to 7

Basic output function print
Format:
  print(‘Things to be printed’)
Multiple data are separated by commas

Variable
  What is a variable?
    A variable is an identifier associated with an object

Naming rules for identifiers:
  Must start with letters or underscores followed by letters or underscores or numbers
  Unable to use Python keywords

  Explain:
    python Case-sensitive variable names
  Examples of legitimate identifiers (variable names)
   abc a1b2 _abc _Abcd var
Illegal identifier (variable name):
  1a2b $abc +a #sde @sdfh
pythonKeyword
  True, False, None, is, del, if, elif…etc.
Assignment statement
  =
Syntax:
  Variable name = expression
  or
  Variable name 1 = variable name 2 = expression
  or
  Variable name 1, variable name 2 = sequence
Effect:
   1.Create a variable that binds data objects
   2.Modify the binding relationship of one variable to bind another data object
Explain:
  When a variable does not exist, create it and bind it to the object
  When a variable exists, change the quota object bound by the variable
  One variable can bind only one object
  Two variables can bind the same object at the same time
Example:
  pi=3.1415926535897932
pi2=pi #piVariables and Pi2 variables are bound to 3.1415936 at the same time
x=y=100 # xVariables and Y variables are bound to 100 at the same time
x,y=100,200 # Sequential assignment

python Automated memory management in
  a=10000
b=20000
a=a+b # Release 10000 and rebind 30000
c=a # cAt the same time bound to 30000

Practice:
  1.Specify a garden radius r = 9cm
1) Calculate the circumference of a circle
 2)Calculate the area of a circle
2.Variable Exchange Exercise
Two variables are known:
  aBind 10000
bBinding 20000
Question how to exchange bound objects between a and B without creating any new data objects

del Sentence:
  Effect:
    Used to delete variables and to de-associate objects if possible
  Syntax:
    del Variable name
  View all variables in the current scope in interactive mode
  >>>help(‘_main_’)
Quit key: Q
Example:
   a=10000 # Create a variable and bind 10000
print(a) # 10000
del a # Delete a variable and release 10,000 data objects
print(a) # error

Automated memory management and reference counting:
  Each object records several variable bindings (references) itself. When the number of references is zero, the object is destroyed (releasing memory resources). This automatic memory management method is called reference counting.
  Example:
   a=10000
b=a # Two variables bind 10,000 data objects at the same time
del a
del b # At this point, 10,000 data objects will be released.

is/ is not operator
  Effect:
     Determine whether two objects are the same object and return True when they are the same object.
Otherwise return to Flase
Explain:
is not The return value is opposite to is
   x is y
x is not y
id(obj) function
  Effect:
     Returns the address of an object in memory

Small integer object pool
  CPython, Numbers of integers – 5 to 256 always exist in the pool of small integers and are not released and can be reused.
  Example:
     a=100
b=100
a is b # True

Compliance with assignment arithmetic operators
   Operator:
   y+=x Equivalent to y = y + X
y-=x Equivalent to y = Y-X
y*=x Equivalent to y = y*x
y/=x Equivalent to y = Y / X
y//=x Equivalent to y = y//x
y%=x Equivalent to y = y%x
y**=x Equivalent to y = y** x
Example:
  x=100
x=x*2 # x=200

Practice:
   1.In ancient China, it was called 162.1 kilograms. In ancient China, 216 kilograms were several kilograms and several kilograms, which were printed out by program.
   2.It has passed 63320 seconds since the time of 0:00 in the morning. What time, minutes, seconds is it? Write a program and print it out.
   3.Temperature conversion:
  Celsius = 5.0/9.0* (Fahrenheit – 32)
What’s the temperature of 100 degrees Fahrenheit? Write a program to calculate it.
Reflection:
   If you know that the current temperature is Celsius, can you figure out what Fahrenheit temperature is?

 

 

 

 

 

 

 

 

   

 

Link of this Article: Python Foundation – 01

Leave a Reply

Your email address will not be published. Required fields are marked *