Python language programming notes - first week

1.1 program designed basic usage

Computer concept 1.1.1
- Functional
operation on the data, performance data calculation, and input and output processing results are stored and the like.
- editable
automatically and predictable operation of the author's intention to complete a series of instructions.

1.1.2 Development of computer referring to Moore's Law, the performance exponentially
- computer hardware reference scale integrated circuit depends Moore's Law
- the computer running speed and therefore close to the rapid growth in geometric progression
- the computer can support the efficient operation of various types of functions and constantly enrich and develop

1.1.3 Moore's Law Moore's Law
, one -Intel co-founder Gordon Moore in 1965 presented
- the number that can be accommodated per unit area integrated circuit doubles every year
-CPU / GPU memory, hard disk, electronic products and so prices follow Moore law

1.1.4 development of computer
development computer with reference to Moore's Law, the performance exponentially
- the world's only valid for 50 years, and according to the technical development of the field Index
- Computer profound change in human society, or even change the man himself
- for the foreseeable future 30 years, Moore's Law will continue effective

1.1.5 Programming
Programming is computer programmable embodies
- also known as the primary means of programming, the depth of the application of computer programming
- programming has become one of the largest professional social demand today
- a lot of jobs have been taken over by a computer program, programming is survival skills

1.1.6 programming language
programming language is an interactive (AC) for the artificial language
- programming language, also known as programming languages, programming of specific implementation
- programming language is simpler compared to natural language is more rigorous, more precision
- the programming language mainly used for the interaction between humans and computers
- programming language a lot, but not many strong vitality
- there are more than 600 kinds of programming languages, most do not use the
-C language born in 1972 it is a most widely used language
-Python language was born in 1990, it is best to use the most popular language

Programming language implementation 1.1.7
- Source: using a computer program written in a programming language, a human-readable

# 例如:
result = 2 + 3

- the object code: The computer can be executed directly, human-unreadable (excluding experts)
For example: 1,101,001,000,111,011

1.1.8 compiled and interpreted
compiling
source code into object code conversion process
source code compiler → → → object code execution → output
         program input ↗
explanation
converting source code into object code during the same time by one operation one by one.
↘ source code
     interpreter → output
program input ↗

1.1.9 static and scripting languages
depending on the implementation, programming languages fall into two categories.
- Static Language: Use the compiler implementation of programming languages C / C ++ language, Java language.
- scripting language: a programming language interpreter execution. Python language, JavaScript language, PHP language
differences
- static language: a compiler generates object code optimization fuller, programs run faster
- scripting languages: the source code implementation of the time required to maintain and more flexible. Because the source code can be run across multiple platforms.

The basic method of preparation of 1.1.10 program
the IPO
-I: the Input input, the input program
-P: Process main logic processing program
-O: Output output program outputs
the input
 program input
 - file input, a network input, the console input, an input interface, an internal parameter input and the like
 - the beginning of a program input
output
 program output
 - console output, graphical output, file output, network output, operating system and other internal variable output
processing
 processing the input data is a program to calculate the output of the process output
 way out methods collectively known as algorithms, it is the most important part of the program
 algorithm is the soul of a program

Part of the problem of calculating
a problem to be solved, the auxiliary section can be programmed completed.
- calculating computer can only solve the problem, i.e. the problem of calculating portion
- has a problem may in many ways be understood that produce different calculation section
- calculating portion problems generally input, process and output process

Programming To solve this problem
- to analyze problems: computing section analysis of the problem, to think clearly
- demarcation of the border: functional border demarcation issues, planning the IPO
- design algorithms: algorithm design problems, concerns algorithms
- programming: writing computer program problems , programmed
- debug test: run the debugger correctly, run the debugger
- maintenance upgrade: upgrade adaptation of maintenance, updated sound

Streamlining steps to solve computational problems in
three steps to streamline
determine the IPO: clear boundary function computing section
programming: the numerical solution of the design into reality
debugger: Ensure that the program can run properly in the correct logic

1.2Python development environment configuration

1.2.1Python Language Overview
 python translated as "python"
 Python language is owned by Software Foundation Python (PSF)
 PSF is a non-profit organization dedicated to the protection of open source and open development language Python
 Guido Van Rossum is Python language founder
1.2.2Python two kinds of ways to write
 interactive: real-time operating results for each input sentence, grammar exercises for
 file type: bulk execute a set of statements and the results of running the main form, programming

1.3Python syntax element analysis program

Formats Framework 1.3.1 program


```python
# TempConvert.py
TempStr = input("请输入带有符号的温度值:")
if TempStr[-1] in ['F','f']:
    C = (eval(TempStr[0:-1]) - 32)/1.8
    print("转换后的温度是{:.2f}C".format(C))
elif TempStr[-1] in ['C','c']:
    F = 1.8*eval(TempStr[0:-1]) + 32
    print("转换后的温度是{:.2f}F".format(F))
else:
    print("输入格式错误")

(1) indent: indentation framework program of the expression (3,4,5 lines)
- Strict clear: indentation is part of the syntax is not correct indentation running error
- Ownership: code contains between expression and hierarchy the only means
- consistent length: the same procedure can generally use four spaces, one or the TAB
(2) Note: Description of auxiliary information is not a program to be executed (line 1)
- one-line comment: beginning with #, and thereafter is a comment

# 这里是单行注释

- Multi-line comments: The '' 'beginning and end

'''
这里是多行注释第一行
这里是多行注释第二行
'''

1.3.2 Naming and reserved words
(1) variables: to save and placeholder data
- identifier expressed using the variable, the process is called an association identifier naming
TempStr variable names
- can use an equal sign (=) to variable assignment and modification, called the assignment symbol =
tempStr = '82F' # tempStr assigned to a variable "82F"
(2) name: an identifier associated process
- naming rules: uppercase and lowercase letters, digits, and underscore characters such as Chinese combination
- Note: case sensitive, the first character can not be a number, not the same reserved words
(3) reserved words: internal programming language is defined and reserved identifiers used
-Python language has 35 reserved words (also called key word)
if, elif, the else, in
- reserved words are words the basic programming language, case-sensitive
if is a reserved word, If is variable

1.3.3 Data Type: string, integer, floating-point, a listing
- Type Integer: 10,011,101
- string types: '10, 011, 101 '
- the type of list: [10,011.101]
(1) string
- a pair or a single quotes double quotation marks
"123" or "Please enter the temperature value with a negative sign"
- string is an ordered sequence of characters, wherein the characters may be indexed
"Please" is "Please input temperature value with a negative sign" in 0th character
- number string
forward sequence number is incremented, decremented number reverse
string used
- use [] Gets or more of a string of characters
- index: returns a single character string <string> [M]
"Please enter the temperature with the symbol" [0] or tempStr [-1]
- slice: returns a string in a string <string> [M: N]
"Please enter the temperature with the symbol "[1: 3] or tempStr [0: 1]
(2) integer: integer mathematics
32 or -1
(3) floating point: real number mathematics, with the fractional part of
1.8 -1.0 or -1.7, or
(4 ) type a list
- an ordered sequence of zero or more data composed of
[ 'F', 'f' ] denotes two elements 'F' and 'F'
- use reserved Element in determining whether a word in the list
TempStr [-1] in [ 'C ', 'c'] is the same as the former determines an element in the list

1.3.4 statement is a function of
(1) assignment: constituted by a line of code assignment symbol
- assignment statement to assign values to variables new data

C=(eval(Temp[0:1])-32)/1.8 # 右侧运算结果赋给变量C

- the right side of an assignment statement must also act on the data type variable

TempStr = input("") # input()返回一个字符串,TempStr也是字符串

(2) branch statement
statement is determined by the program running direction determination condition
- the use of reserved words if elif else branched structure configured to determine the conditions

if TempStr[-1] in ['F','f']: #如果条件为Ture则执行冒号后语句

- each row reserved word last present a colon (:), part of the syntax of the
 colon and subsequent indentation to indicate the condition of subsequent statements affiliations
(3) function
to generate output based on different functional process input parameter
- similar mathematics function, Y = F (X)
Print ( "input format error") # printout "input format error"
- function using <function name> (<parameter>) mode using
eval (tempStr [0: -1] ) # tempStr [0: -1] is a parameter
input and output 1.3.5Python program
(1) input function input ()
obtain user input from the console function
-input () function using the format
<variable> = input (<character message string>)
- user input information stored in the character string type <variable> in

input("请输入") # TempStr保存用户的信息

(2) Output function print ()
as a string of functions to the console output
 -print () function using the format of the basic
  print (<string or string variable analog output>)
 - a string type only quotes uses internally, no output quotes

print("输入格式有误") # 向控制台输出 输入格式有误

 -print () function formatted
  print ( "converted temperature is {: .2f} C" .format ©)
   {} denotes the groove, the groove is filled into the subsequent variables
   {: .2f} represents the variable C is filled into the 2 after the decimal point position
   if the value of C is 123.456789, the output result is:
   temperature converted to 123.45C
(. 3) evaluation function eval ()
to remove the outermost parameters quoted statement and performs the remaining functions
 -EVAL () function the basic format using
  eval (<string or string variable>)

>>> eval("1")
1
>>> eval("1+2")
>>> eval('"1+2"')
'1+2'
>>> eval('print("Hello")')
Hello
eval(TempStr[0:-1])
# 如果TempStr[0:-1]值是"12.3",输出是:12.3
Released four original articles · won praise 2 · Views 373

Guess you like

Origin blog.csdn.net/luzining/article/details/104879114