Life is short, I use Python---python to learn four of the Forth
Haha, then, let's go! We introduce the underlying---statements of our logic programming, which is our small partner in programming, it is the foundation of the foundation, it is the focus of emphasis!! So baby take a good look at this chapter Oh, we will combine several examples to deepen our understanding of the statement.
1. Let us first introduce the conditional judgment statement if----else, if--elif--else statement (it is worth noting that Python does not have a switch---case for the Conditional Judgment statement)
A) Let's take a look at if----else (we test with pycharm)
Basic usage of the IF--else statement
If condition 1:
program Block
Else Condition 2:
Program block
We found that a is greater than B, so the program executes else this paragraph, so the program output is "A is eldest brother"
b) Let's take a look at If--elif--else (we use pycharm to test)
Basic usage of the IF--else statement
If condition 1:
Program block
Elif Condition 2:
Program block
Elif Condition 3:
Program block
Else Condition 4
Program block
Cute little friends, isn't it easy? But it's important to note that our numerical judgments are equal to the "= =" number.
Here we introduce loop statements while and for loops
let's start with the while loop and see below syntax for While Loop
While judging condition:
Execute statement ...
No more nonsense, let's start with an example.
Let's see how the results work
We found that count increased from 0 to 8, and when Count equals 9 jumped out of the loop
The terrorize for the For loop is explained below
So let's start with the For loop string, let's take a look at the first example.
Let's have a look at the output of it.
Yes, see, we printed out every single character in the string with I.
So let's take a look at how the digital loop comes in.
Here first to tell you about our range (X,y,step) function, in this function, we have three parameters, the first parameter is the start of the loop, the second parameter is the end of the loop value, the third step as the name implies, we know, it is used to represent the step, it says, Once the loop has been increased a few times, step can not write, do not write, it means the step is 1
So, let's take a look at the example, for the use of the In range ()
We read this code carefully, and we found that it jumped out of the loop from 1-4 to 5, so I printed 1-4.
Isn't it amazing?
We can also reverse the use of a For loop
For example, the following example
Let's look at its output.
We found that it is reverse output, is not very useful?
Well, here we are today, the next section we talk about nested use for loops, basics of arrays, bubbling sort, and other examples
Life is short, I use Python---python to learn four notes