How Linux Ops learns Python programming

Source: Internet
Author: User

How Linux Ops learns Python programming


    • Never write code, you can write code independently to solve problems. This question is very important! Blindly learn the so-called project, and finally

      Or do not write code to solve the problem yourself. First, the Independent can write code to solve the problem, and then through the project to strengthen training.

    • Operation and maintenance must understand the development, especially the development of Python, has formed a consensus, do not understand the development of operations, the road will be more narrow.


Some operations have encountered difficulties are: some even books do not understand, some books can be read, others write simple code can also read, but they will not write code to solve the problem.

I think learning programming is more than learning grammar, need to learn the algorithm (computational thinking, problem-solving methods, programming ideas).

What is computational thinking:

The concept of computational thinking (computational thinking) is a natural product of the development of computer science.

The first clear use of this concept was Professor Zhou Yijien (Jeannette M. Wing), Carnegie Mellon University, USA.

Computational thinking is the use of the basic concept of computer science to solve problems, design systems and understand human behavior;

The fundamental content of computational thinking is that its essence is abstraction and automation.

Programming thinking, in fact, is the concrete embodiment of computational thinking, the use of grammar to express the problem-solving methods, algorithms.


Let's talk about how to learn python.

1, buy a good book, recommended to see "Python Core Programming 2nd Edition", a book is enough.

2, while reading, need to knock code, every code in the book needs to be knocked over, the process of knocking, to encounter problems. Have a problem and try to

Solve, can improve.

3, also need to do the appropriate exercises to strengthen learning.

4, Python has a variety of programming paradigms, process oriented, object-oriented, functional programming and so on. It is recommended to start with a process-oriented study.

Some friends are too ambitious, even the basic logic expression is not clear, cycle and judgment are not clear, want to learn Django.

Question one:

Output the following style 1,2,3,4,5,6,7,8,9,10

Many beginners, will write the following code,

For I in range (1, 11):

Print str (i) + ",",

The output results are 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,

It is baisibuxie how to not output the last comma. Huanggo tells you that when reading a book know if judgment statement, but the actual application is not good.

Analyze This style 1,2,3,4,5,6,7,8,9,10 the last one without a comma, preceded by a comma, this is obviously a judgment ah.

So the code writes like this:

n = 10

For I in range (1, n+1):

If I < n:

Print str (i) + ",",

Else

Print str (i)

Question two:

Counting loops, I believe that most of the toy code in the book can be read.

The following question, beginners do not necessarily think of counting loops to solve this problem.

Code One:

A few m text files that need to be written to a new file every 100 lines.

Do not underestimate the counting cycle, with the counting loop and the judgment statement can solve this problem.

# Coding:utf-8

With open (' Dist_1.txt ', ' R ') as F1, open (' Dist_new.txt ', ' W ') as F2:

i = 0

For line in F1:

i + = 1

If I% 100 = = 0:

F2.write (line)

Code two:

I would like to ask a log text file has 2000 lines, I want to extract the 100 lines to 200 lines, how to do?

You can try the following method.

Don't underestimate the while counting cycle, in fact it can be used to do a lot of things.

#coding: Utf-8

i = 0

file1 = open ("Test.txt", "R")

File2 = open ("OUT.txt", "W")

While True:

line = File1.readline ()

i + = 1

If 100<=i and i<=200:

File2.write (line)

If I >200:

Break

If not line:

Break

File1.close ()

File2.close ()

5, function abstraction, need to master the big problem to solve for small problems, each small problem with the function to resolve, the integration of the big problem solved.

6. Object-oriented class abstraction, class is the blueprint of an object composed of attribute plus methods. is modeled with object-oriented thinking.

Summary: There is no programming ideas, is the key to their own writing code. Master Some common simple algorithms: Exhaustive method, dichotomy method, recursive algorithm, recursive algorithm, backtracking algorithm and so on;

The most important thing is to solve the problem of training, have ideas, can solve the problem independently, in the workplace invincible!


How Linux Ops learns Python programming

Related Article

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.