& Lt; Python basic tutorial & gt; learning notes | Chapter 1 | basic knowledge, Chapter 2 of python

Source: Internet
Author: User

<Python basic tutorial> learning notes | chapter 01st | basic knowledge, python chapter 01st

This learning note is mainly used to record some Key points in the course of learning <Python basics>, or the content that you do not understand may be a bit messy, but it is more practical, it is easy to find.


Chapter 2: Basic knowledge

------

Jython: Java Implementation of Python. It runs in JVM and is relatively stable, but lags behind Python. The current version is 2.5, which is used in TA (Python + Robot ).

IronPython: Python C # implementation, running in the Common Language Runtime, faster than Python

>>> From _ future _ import division
>>> 1/2
0.5

If you perform a direct operation, the value is 0. Unless you enter 1/2. 0, Python calculates the number of points.

------

Variable name: including letters, numbers, and underscores. It cannot start with a number. So the following statements are correct:

Correct: file_1; dict2; _ del

Error: 9jin; hello world; g-z

------

Differences between input and raw_input:

1. if the input is a number, after the input, the data type is int and raw_input, only the numeric type can be used. int (str1) must be used for conversion. This should be noted in programming.

>>> I = input ('enter here :')
Enter here: 32
>>> Type (I)
<Type 'int'>
>>> J = raw_input ('enter here :')
Enter here: 43
>>> Type (j)
<Type 'str'>


>>> Raw_input ('enter a number :')
Enter a number: 4
'4'
>>> Input ('enter a number :')
Enter a number: 4
4

2. input cannot contain special characters or translated characters. Otherwise, an error is returned. raw_input can.

>>> A = input ('enter here :')
Enter here: \ n \ t

Note that single quotation marks or double quotation marks must be added for string input.
>>> A = input ("Enter string :")
Enter string: 'hello'

Traceback (most recent call last ):
File "<pyshell #75>", line 1, in <module>
A = input ('enter here :')
File "<string>", line 1
\ N \ t
^
SyntaxError: unexpected character after line continuation character
>>> B = raw_input ('enter here :')
Enter here: * \ n \ c \ t
>>>

3. Double-click the program to run under Win. If you want to see the interactive interface, add raw_input ('Press Enter to Exit <> ') at the bottom to avoid a flash of the program ')

------

>>> Round (1/2) # rounding
1.0

>>> Math. floor (1.1), math. floor (-1.1) # The floor is always small. You can also know it by name. The floor, of course, is the bottom layer.

(1.0,-2.0)

------

An error is returned when the square root of a negative number is obtained.

>>> Import math
>>> Math. sqrt (-1)
Traceback (most recent call last ):
File "<pyshell #94>", line 1, in <module>
Math. sqrt (-1)
ValueError: math domain error

Must use cmath

>>> Import cmath
>>> Cmath. sqrt
<Built-in function sqrt>
>>> Cmath. sqrt (-1)
1j

>>> (1 + 2j) * (3-4j) # complex operations
(11 + 2j)

------

Shebang

If you want the Python script to run like a normal script, you can add #! At the beginning of the line #!, Use chmod to add executable permissions

For example:

#! /Usr/bin/env python

Or

#! /Usr/bin/python

$ Chmod + x./hello. py

$ Hello. py # If this parameter is not added, it must be./hello. py or python hello. py.

------

If the single quotation mark still contains the single quotation mark, it must be translated.

''''' Three quotation marks. You can output String concatenation as needed. The WYSIWYG mode can also contain single quotation marks and double quotation marks.

'Let \'s go'

''Let's go''

>>> Print "" This is a first programing...
Print "Hello, World! "
Print "Let's Go"

"""

Output result:

This is a first programing...
Print "Hello, World! "
Print "Let's Go"


>>> Print str ("Hello, World! ")
Hello, World!
>>> Print repr ("Hello, World! ")
'Hello, World! '

Str (), repr, and quotation marks are the three methods to convert values to variable type.

Use ''back quotes to calculate arithmetic values or reference numeric variables.

>>> Print '2 + 3'
5

>>> Temp = 2
>>> Print "Temp's value is:", temp
Temp's value is: 2
>>> Print "Temp's value is:" + str (temp)
Temp's value is: 2
>>> Print "Temp's value is:" + 'temp'
Temp's value is: 2

>>> Print "Temp's value is:" + repr (temp)
Temp's value is: 2

------

\ Escape is used in a row. For example, \ n indicates line breaks and \ t tabs. It can be ignored at the end of a row and is mainly used for multi-row input. For example:

>>> 1 + 2 + 3 \
-4/2 \
* 2% 3
5.0

>>> Print "C :\\ python27"
C: \ python27

That is to say, \

>>> Print "This is illegal .\"
SyntaxError: EOL while scanning string literal

If you really want to express it, you need:

Print r 'C: \ python27 \ lib \ test \ pack1 \ pack2 \ pack3 ''\\'
C: \ python27 \ lib \ test \ pack1 \ pack2 \ pack3 \

If it is a long path, it will be more troublesome to input it. If it is too troublesome, add r, raw, and the original string to the front.

The original string is very useful, especially in regular expression matching.

>>> Print 'C: \ python27 \ lib \ test \ pack1 \ pack2 \ pack3'
C: \ python27 \ lib \ test \ pack1 \ pack2 \ pack3
>>> Print r'c: \ python27 \ lib \ test \ pack1 \ pack2 \ pack3'
C: \ python27 \ lib \ test \ pack1 \ pack2 \ pack3


Generally, python uses 8-bit ASCII to store data. If you want to use Unicode characters for storage, you can store 16-bit data and more characters. The user is similar to r

>>> U'hello, World! '
U'hello, World! '

Main built-in functions in this section

Function Name example

========================================================== ======================================

Abs (number) returns the absolute value of A number> abs (-2) #2

Cmath. sqrt (number) returns the square root of the number >>> cmath. sqrt (-4) # 2j

Float (object) converts string and number to a non-point type> float ('20140901') #123

Help () provides help interactive interface >>> help (math. cmath) # Or help ()

Input (prompt) to get user input >>> input ("Enter nuber:") # See the previous section

Raw_input (prompt) is used to obtain user input. For example,> raw_input ("Enter:") # See the preceding section.

Long (object) converts string and number to long integer type> long ('000000') # 12345L

Math. ceil (number) indicates the upper part of the returned number, no-point type> math. ceil (1.4) #2.0

Math. floor (number): return the lower part of the number, no point type> math. floor (-1.6) #-2.0

Pow (x, y [, z]) returns the y Power of x, and then modulo z> pow (, 4) #1

String method returned by repr (object) >>> repr (1234) #'123'

Str (object) converts a value to a string >>> str (12345) #'123'

Round (number [, ndigit]) performs a rounding operation based on the specified precision number >>> round (3.14) #3.0


What is the concept of basic knowledge?

Hello, I'm glad to answer your question.

Only through basic knowledge can we learn advanced knowledge based on the corresponding foundation. Basic knowledge must be applied to all questions.
The higher formula can only be derived from the basic formula.

For example, only the basic knowledge of Newton's three laws can solve the mechanical problem.
Optical problems can be solved only after learning about the refraction and reflection dispersion of light
Only after learning the convex lens refraction law can we solve the convex lens problem.

Hope to adopt
 
Basic procurement knowledge

What is procurement: it refers to the purchase behavior of obtaining materials and services through exchange, and obtaining quality and quantity of resources for the enterprise to operate at the right time, place, and price.
Essential capabilities of purchasers: Cost Awareness and value analysis, prediction, presentation, good interpersonal communication and coordination, and professional knowledge.
What kind of good purchasers are: In addition to the essential capabilities of purchasers, they must have a reasonable procurement plan, abide by the 5R principle, select appropriate suppliers, and add them to management for continuous improvement. Reducing procurement costs without affecting enterprises' normal production.
Responsibilities of purchasers: procurement plan and demand confirmation, supplier selection and management, procurement quantity control, procurement quality control, procurement price control, delivery date control, procurement cost control, procurement contract management, and procurement record management.
Procurement process: Collect information, make an inquiry, price comparison, price negotiation, evaluation, sample query, decision, purchase, order, coordination and communication, reminder, purchase inspection, and payment arrangement.
Purchasers have the following responsibilities:
1. Issuance of purchase orders.
2. Control the material delivery period.
3. Investigate the material market.
4. Check the quality and quantity of incoming materials.
5. Handling of abnormal feed quality and quantity.
6. communicate and coordinate with suppliers on delivery time and delivery volume.
Basic Quality Requirements of purchasers:
A. Strong Working Ability
Procurement is a complex and demanding task, and the basic work capabilities that purchasers should possess are also quite diverse. Purchasers must have a high level of analysis, prediction, presentation, and professional knowledge.
A-1 analysis capability
Since purchasers often face the selection and formulation of many different strategies, for example, materials specifications, product purchase decisions, prices acceptable to enterprises, transportation and storage of materials, and management can receive responses from consumers. Therefore, purchasers should be able to use analysis tools and make effective decisions based on analysis results.
First of all, procurement expenditure is the main part of the enterprise's manufacturing costs. Therefore, purchasers must be cost aware, carefully calculated, and cannot "big ". Second, we must have the concept of "cost effectiveness". For example, we can buy items with poor quality or no practical value. Compare the input (cost) with the return report (Usage Status, validity period, loss, number of repairs, etc.) at any time.
In addition, there should be analysis skills for the content of the quote, and the comparison of the "Total price" cannot be made. It must be on the same basis, analyze and Judge items one by one (including raw materials, labor, tools, taxes, profits, delivery time, and payment conditions.
A-2 prediction capability
In the modern dynamic economy, the procurement price and supply quantity of materials are subject to frequent changes. Purchasers should be able to determine whether there are sufficient sources of goods based on various production and sales materials. Through the contact with suppliers, they should look at the possible supply of materials from their "sales" attitude; from the rise and fall of material prices, estimate the impact of procurement costs. In short, purchasers must broaden their horizons and have the ability to make sense of what they say, so as to develop predicate countermeasures against future supply trends of materials.
A-3 expression ability
Purchasers must be able to correctly and clearly express the various procurement conditions, such as specifications, quantities, prices, delivery periods, and payment methods, in both language and text, avoid ambiguity and misunderstanding. In the face of busy procurement work, procurement personnel must be able to express themselves in a short talk and concise manner, so as not to waste time. It is an expression of skill that must be exercised by the purchasing personnel.
B. Some knowledge and experience
Purchasers, especially management personnel, should have at least a college degree or above. Because students who have received formal education or training courses below, their professional knowledge and skills can better meet the needs of procurement work. In addition, it is best for purchasers to have business knowledge, such as enterprise management, Circulation Management, popular products or marketing departments, he is also an expert in product information, statistics, marketing, and business personnel management.
B-1. Product Knowledge
No matter which kind of material is purchased, you must have a basic understanding of the subject matter purchased by his/her supervisor. We know that a person who has been engaged in procurement of chemical machinery for many years will switch to procurement of electronic components for work needs. Although he has been engaged in procurement for many years, he will still feel a little powerless, if he wants to adapt to the new role as soon as possible ...... remaining full text>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.