Write the first python program

Write the first python program

Let's write now

Our first python program

The first action we first open Sublime

Windows key into sub

Sublime Text 3 was found

This is the software we write the program, open

All gray

We directly enter print 100

Archive now

File

Save

Just archive

There is a shortcut on the right called ctrl s

I suggest everyone use this shortcut ctrl s

I now save to desktop

Create a folder

We are all the same in this folder

Unified coding coding folder

After I go in the coding folder,

My file name is called 123.py

The end of .py is very important

Is to tell the computer that this is a python file

Archive

It has color now

Light blue and purple

So how do we execute this file?

We open cmd

Use the Windows key to open

CMD

Black command prompt

Let ’s zoom out to the desktop first

The created folder coding we open

Then now we have to copy and copy

I click here

I chose all the paths

Then I can right click to copy

I can also press ctrl c to copy

We will now copy this path

This path is inside our computer

The address of this folder

So after we copied this path

Back to cmd, put cd space

Then paste

Paste your folder path

This is the path of my coding folder

Press Enter

cmd is over there

Our present

Just stand inside this coding folder

We can see this file now 123.py

We can execute it later

cd means change directory

Change folder meaning

directory is just a computer term

Actually it means the folder

Then we change the folder

Where to change to this address

So cmd is now at this new address

So that we can execute our program

Type in python 123.py

python space filename

Is how we execute the python program

Press Enter to print out 100 right

As long as you have a way to successfully print 100

It means your successful execution

The first python file of your life

Remember oh python space file name

Is how we execute the python program

The premise is that you have to cd in first

Then look at this program

Why it will print 100

Because we wrote this print

print is a built-in function of python

Is to make it display text

Printed in cmd

It just means printed

In normal life we ​​hear print

I think of the printing of the list machine, etc.

Print in python is just to put it

Just show

So we now call it 100

If I change to 1000 now

I will save it after I change it to 1000

ctrl s archive right

What should I do after I come back to cmd

Execute python 123.py again, right

Enter printed 1000

So we can have a way now

Modify our code and run it again

Do you feel that every time you hit

python 123.py is troublesome

It's troublesome to hit it every time, right?

There is a shortcut key

You press up, down, left, up

You can go back to the previous instruction

Go back to the previous instruction

Enter

So that we can repeat the execution

This is what we practice

The first python program

And we soon realized

What is the function of print

print just prints things

If you are in the future

If you forgot to execute the python program

Remember to watch this video

After we open cmd

First cd to the directory of your folder

Then type the python space file name

You can perform two steps

Supplementary explanation

Just now if some students are curious about your folder

Obviously saved 123.py

But you can't see the end of that .py

File name only shows 123

Why is this so

And my computer shows 123.py

It ’s just because I have turned on that function.

Look at me, check me to check here

Then you see the extension is right

I turned it off

No.py ends

If I check the extension again

It put this extension

.py extension is displayed

That's all

You can open it and close it

It doesn't matter

Simply put, if your ending is not displayed.py

It's actually correct

As long as you have the correct deposit when saving

Then you can see the color here

Light blue purple is correct

Published 6 original articles · Likes0 · Visits 6

Guess you like

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