Python Learning Notes-first day (Basics of Linux basic operations and Python)

Source: Internet
Author: User
Tags save file kali linux

I have two computers, a desk-top laptop, and the notebook is an old computer. This machine is loaded with Kali Linux. The code that was written directly in the Python interpreter before daytime learning. But if you want to write a file, you can't. So I got a elementaryos virtual machine on the desktop to write.

First of all, tell me about My Learning method. That is the constant knock, the article inside the key words to grasp. such as if (judgment) and so on. And then, I will not remember so much at the beginning, but you forget to look at what you forget, and then knock. I remember the error after almost, because some characters or something is not written. This is the details of the problem, and then re-knock, and so on again and again knock. The core points are captured and the code is remembered. So you've learned it.

Now let's talk about the basic operation under the Linux virtual machine.

The first is to add a folder, do not know why I switch to the root user or not directly in the folder to create folders or create files, so can only hit the command to create.

Create Folder command:

mkdir file name

For example:

mkdir python

You can see that the creation was successful, but LS has too many files or folders. Switch directly to the created directory to see if there is

The above hint does not have that file or the directory, is I own the wrong call. As to what is wrong, find out for yourself.

The switch is successful, LS is not a file. Then it's up to you to create and edit the file.

The command is as follows:

Nano file name

For example:

The Nano editor is also opened when it is created, and can be edited. Here's how to say the Nano Editor:

Ctrl+x Saving files

Prompts you if you want to save input y carriage.

Save File name Enter

Can. Then you can see the LS.

See figure for details:

I'm writing this one. Gets the user input and then makes a judgment output

Assign Raw_input ("xxx") to the variable Userinput

If you start judging, the variable plus the. Lower () function makes the contents of the user input lowercase (python is case-sensitive).

Two equals sign = = the string (string) that determines whether the content entered by the user equals = =

In.

The judgment variable userinput the user input into lowercase. The lower () function. The next colon: if the judgment is positive, the input should be echoed back to the user if it is judged.

Remember the TAB key. If you determine the right, that is, the access is equal to string. Then output print "XXX"

Then Else.else's translation is otherwise, the other means. That is, if the user's input is not equal to string. Then it's the other one, and you're going to use else this time. The colon, after all, also needs to output the content.

And then there's elif. This function can be used multiple times, how many times you want, after all, the user is diverse. The content is different. It is also necessary to output a sentence to meet the user, isn't it?

Okay, we've finished the code. Let's continue to take a look at Linux's basic operations.

This time after you have finished writing the code.

Press the Ctrl+x

If you do not have this file you will be prompted whether to save. I am present in this file, so will he prompt you to update it? Enter Y

Continue to enter.

Learned to create folders, create/edit files.

Well, then, finally, delete it.

Delete file:-rm-f specified file

Delete folder:-RM-RF Specifies the directory (note that all must be root paths. For example:/usr/lib/python2.7/xxx.)

Python Learning Notes-first day (Basics of Linux basic operations and Python)

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.