Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the process of learning Python?

2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "what is the process of learning Python". In daily operation, I believe that many people have doubts about learning the process of Python. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts of "what is the process of learning Python?" Next, please follow the editor to study!

Hello World!

Writing down Hello World is the first thing you do when learning any programming language. In addition to getting you excited about the first time your code is running, it will also help you check whether the current running environment is working properly.

The first program we run!

Novice learning, Python tutorials / tools / methods / troubleshooting + V:itz992 focus

Readability-We have noticed that the print instruction uses "print", which may be obvious, but believe me, in other programming languages, it can be troublesome, such as "System.out.println".

This command structure is very important. Print is a function, a function that accepts input in the computer world, and it also generates output. This function will not return anything, but it will print anything you want to the screen.

Variable

Variables are the bricks of programming, some are standard variables built into the system, such as numbers, strings, list values, and some are customizable. We will create custom variables at the end of the article.

A variable, like a container, is a name that represents one or more values. The point is, it's really just a container!

Figures

Now the meaning of the variable should be self-evident. To declare a variable is to assign a value to the variable. If you want to be a power (power), you only need to use "*". The order of operation is like junior high school math, writing from left to right, priority in parentheses. Multiply and divide first, then add and subtract, pay attention to the order, this is very important!

String

String should be a broader topic now, the number of functions is unlimited, but the basic content is here, adding strings is just merging, you can observe its substrings in string variables, using slices, determine the location (for example, from 0-2 or any range you like).

The "len" function displays the length of an object, and in this way, we can extract the substring "Hello World" from the initial string. Please think about it. I don't want to cram you with content, which will ruin the whole learning experience.

Lists, tuples, dictionaries and collections

Lists are fast and good at storing and manipulating large amounts of data, and are one of the most commonly used objects in Python.

Keep in mind that in most cases, the operation of the list changes itself, and the simple copy list (shallow copy) is not really copied (deep copy), which is a little ahead of time, but if you want to copy a list, do this:

(the second line of the above operation actually copies the storage address, lst3 and lst are essentially the same object; the third line copies the value, not the storage address.)

Trust me, you'll thank me later!

There are many tuples, collections and dictionaries to introduce, but the space is limited. I will introduce some basic uses.

Count in a dictionary; tuples prevent values from being tampered with; collections do not allow duplicate values and process data quickly.

Process control

Flow control is just a fancy name for if-else statements.

Elif- executes only when the if statement is false.

Indent, indent, indent!

I can no longer emphasize how many mistakes new developers in Python have made for this reason alone. These four spaces determine the statement block. Note the position of the print statement in the if block, and the if statement will do nothing if it is removed from the if block.

Another important thing is that = = does not assign a value, it can only calculate True and False.

"elif" appears only when the if statement fails, to avoid testing when the number is greater than 5 and then testing again when the number is greater than 8 (just an example).

Combining and and or is a way to check multiple statements.

Loop and iteration

You can iterate through lists, meta-ancestors, dictionaries, or even strings. Here's how it works:

The loop allows you to rewrite anything you want many times. You only need to write once, and then make the code stop after the number of times you want (for example, while loop)

Or if you want to process only one data at a time iteratively, you can use the animel method in the figure above.

Function

Today's content is coming to an end, please pay attention.

The function requires input, does something with the input, and then sends back to the user feedback-- that is, output.

If you can remember this sentence, then this is most of the work you will do.

Function allows us to perform multiple operations over and over again without having to repeat the narrative. And it makes the code more readable, and when you read this line of code-- if test_even, it's easy to understand that this function is to check whether a number is even. This way readers can better understand the code you write. Readability is very important.

Class

Now the class is the constituent element of the custom object, think of it as an architectural blueprint, it will teach you how to build a building.

You can build two buildings according to this blueprint, they are both the same building, but not the same building, which is very important, a class describes a thing, an object, but it is not the object itself.

OOP (object-oriented programming) is a profound and advanced topic, the first paragraph represents its basic concept, but it is a problem worth discussing in a series of articles, not an article.

Now an object has two main characteristics, they are properties and functions (methods), "what it is and what it can do."

Finally, the blueprint is the Cat class, with which I can create an object (cats), as shown below.

The self attribute refers to the object, not the class, basically, the age of the cat, or the sex of the cat, so it is called self, which refers to the object.

We can create custom functions like play, which can do nothing in this case, but we can also rewrite built-in python functions, such as add (in this case, I have them generate a new cat object) or _ _ repr__ to replace the print function.

This explanation is just the tip of the iceberg, but you have to get started somewhere.

At this point, the study of "what is the process of learning Python" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report