Announcement (creation, creation)

Declare

We first put this 123.py

Delete all

Then we type x = 5

x = 5 archive

If you save this file when you save

Just press the fork or cancel

This is just because the Sublime we use is

Free version so it sometimes

Will encourage you to donate or buy

We just press the fork

How to execute our program
back to cmd

Then type python space file name file name is 123.py

Then press Enter to run

You have to remember

If your path is correct

If you forget how to put the path

If you cd to the right place

You have to go back to see that

Run the first python file

Remember the python space when executing

Just press Enter for your file name

Then I press Enter

Nothing is printed after repeated execution

Then we are back now Sublime

Print it out i print x

Is the meaning of printing out my x, right?

print is to print things

Then I will print x now

Then I remember you saw this circle

On behalf of me

After my ctrl s archived it changed to fork

Then i come back cmd

I press on the implementation

Becomes 5

It printed x

it is good

Ok, we now know that print x can print 5

Because x is 5

Key announcement

What is an announcement

宣告 in English is declare declare

Declare therecreationthe meaning of

This word is quite important

creation

When we type x = 5

This program has created x

You imagine this world

You imagine that this world was originally nothing

You imagine that Martian sky is unique

It ’s all sand and no one

No machine is empty

When we enter x = 5

Our world produces x

Then I will draw x into a box

I put something in our world

Draw into boxes

Then the name of this box is x

It contains 5

The name of this box is x

Then it contains 5

I didn't have this box

After we enter x = 5

Our world has this box

So this is why it feels creative

Let me describe another example for you

Suppose I told you today

Trump is the President of the United States Trump is the President of the United States

Then you think about seeing a baby

When a baby is born, it knows nothing

He has nothing to do with this world

Don't know anything

Then you tell this baby

Trump is the President of the United States

Does the baby know

There is Trump in the world

Then he is the President of the United States

He didn't know that Trump was there

He heard you saying that Trump is equal to the President of the United States

He said Oh, there are Trumps in the world

Just like this feeling

When we enter x = 5

We create x

Then we know it is 5

Its value is 5

We do n’t have to be too persistent about part of this term

You just need to know

Just declare that you have a creative meaning

Then you have to realize this feeling

If we now put these

These words are not code, so we delete them first

Then you think about it, if I enter another line

x=10

How many boxes do you think in this world

We created a box

Still created two boxes

What do you think

the answer is

One

Still one

Come and explain to you now

Now there is a box

Then x and then this box contains 5

When we meet the first

Now is the third line when we meet the third line

When x = 10

We just wiped out this 5

Changed to 10 only

We are just going to change its content

Right, so you x = 5 and x = 10

What we are talking about x

Is talking about the same thing, this box

So what you have to understand here is that

When our code first encountered

When x = 5

Only in the first encounter will there be creation

After that, you will only change

Only the first encounter will create

After that, if you encounter it again, it will only change.

So if I write another x =

x=10000 1000 1000

Then we just say change 5 to 10

Then it was changed to 1000

Not so hard

What if I want to create a second box

I have to use a different name

For example

y = 2

Then our program runs

You first create a box which is x

Then it was originally 5

Change it to 10 and change it to 1000

And then on the fifth line

It produces another box which is y

The name of this box is y

Then it contains 2

It contains 2

Just like this, there are two boxes in this world

x and y

Okay, let me explain in terms

But what

I do n’t think people need to be too attached to these terms

You do n’t have to bring a laptop or something

Hard to recite those words

You only need to listen a few more times to understand

The terms x and y are called variables

English is called variable

Can also be abbreviated as var var

Why is it called a variable because it can change

For example, look at

At first x was 5

Later it becomes 10

Later it became 1000 and it was changing

So it is called a variable

Its origin is such that it can change

What about the right side

2 1000 10 these are the values

English is called value value

The x and y on the left are called variables

The 10 1000 2 on the right is called value

If you read the whole sentence

This x = 5 read the whole sentence

Should be read like this

We declare a variable

Its name is x

Then its value is 5

We create a box

That is, we declare a box

Its name is x and its value is 5

So the value is in it

You can imagine the inner content of a person

Just its value

A person's inner x's inner is 5

What about the third line

Again x

Is it x again?

We do n’t create because we already have x

This world already has the name x

How to read this x = 10

This is called we set the value of x to 10

The third line is set to 10

Because we haven't created anymore

So our third line is no longer declared

We will read that we set the value of x to 10

So we changed this 5 to 10

It actually has a term called assignment

assignment is Chinese called setting instruction

Each of these lines is a set instruction

x = 5 x = 10 y = 1000

Not x = 1000 y = 2

Each of these lines is an assignment

How to judge it is an assignment

Because we have an equal sign

That means me

We store 5 in x

You understand it as an equal sign

Save right to left

Save 5 to x

Read as we set the value of x to 5

10 save to x

That is, we set the value of x to 10

1000 saved to x read

We set the value of x to 1000

For example, if I type now

y = 1000

I can tell you

We now set the value of y to 1000

So those assignment variable value

Don't be too obsessed with memorizing its definition

Let's review this program now

We come line by line

Determine what it is doing

The first line x = 5

Because this is the first time we see x

So we have announced the creation of action

Create a box

Its name is x and its value is 5

We printed the second line

In the third line we set the value of x to 10

So I changed it to 10

In the fourth line, we set the value of x to 1000

I changed it again to 1000

The fifth line is the first time we have seen y in our life

So we have announced actions

We create y

A box called y, the value in it is 2

The sixth line y = 1000

We set the value of y to 1000

So we read these six lines like this

Then think about it

If we print now

and

What will be printed

Print out the value of y

The value of y is not just 1000

Let's try

Print out x there is printed out x there is printed out y

Then we perform a look

python 123.py

Then you see it prints 5 and 1000

Why it prints 5

Because x is 5 right

x later became 10 became 1000

That's what happened later

When it was printed, x was still 5

Because it reads from top to bottom

Directly after the execution of the first line

Execute the second line

Later it became 10

Later it became 1000

Then the last printed yy is 1000

So 5 and 1000 are not wrong

Then if you think about it,

with

What will happen

Try it on Enter

An error occurred

NameError

z is not defined

Is that z has not been defined

Simply put, we are still

There is no z in this world

Look at the above, we obviously only have x and y

How can we call it print z

We haven't created z yet

So when we want to ask it to print a

When we haven't created something

There will be this NameError

Then it will tell you

The name you gave has not been defined yet

That's it

Published 6 original articles · Likes0 · Visits 6

Guess you like

Origin blog.csdn.net/weixin_46942229/article/details/105454364