Python notes (i)

Source: Internet
Author: User

I am a 211 College software engineering Junior students, because the previous period of time has been looking for internship company. The written exam interviewed a lot of companies, although there is a certain foundation, but still by some corporate interviewers like dog abuse. Finally found a better reputation of foreign companies, the main focus on information security. This time has been idle, intends to learn some new knowledge, strengthen yourself. Contact Python today, and now summarize today's harvest. You will then update your blog along with your plans. Welcome to Bo Friends pointing!

Less nonsense, the power of the Python language I am not very clear now, in terms of the recruitment requirements of major IT companies, almost all need to be familiar with Python.

  Environment configuration:

In the official website (python.org/download) Download the latest version, I downloaded is 3.4.3. Now come down after the installation. The installation is simple, just follow the prompts and keep going. After installation, if you want to invoke Python from the Windows command line, you need to set the correct path variable in the system variable. I'm installing Python on D:\software\Python, then after it's added to the path variable. We can then open the Python interpreter by clicking "Run" and entering Python. As follows:

You can also use the editor that comes with the download time to edit idle. Of course I don't use both, I'm used to using notepad++, so let's talk about editing the Python script in notepad++. In notepad++ plug-in management, download the PYNPP plugin, then press F5 in the main layout and add the following batch command in the box that pops up: cmd/k D:\software\Python\python.exe "$ (full_current_ PATH) "& PAUSE & EXIT, then you can edit and run Python in notepad++.

  Basic concepts:

If you know other programming languages such as Java,c, then Python's syntax is easier to master, and it's not very difficult in itself. The following highlights its special point.

1. String: In Python strings can use single quotes, double quotes, or even three quotation marks. Single and double quotes work exactly the same, but if you have quotes in the printed string, you must use the escape symbol ' \ ', for example, we want to print out: He is a ' gay '. Then the statement should look like this: print ("He is a \ ' gay\ '"). but for the three quotes (' '), we can freely use single and double quotation marks in them.

2. Object: Python becomes the object of anything that is used in the program. So Python is an extremely complete object-oriented one.

3. Logical and Physical lines: the physical line is what we see in programming, the logical line is a single statement that Python sees, and Python assumes that each physical row corresponds to a logical line. That is, thepython default is one statement per line . In Python, there is no need to use semicolons between our statements and statements (;), because the Python default per line is a statement. This means that the following two pieces of code are the same: 1.i = 5 2.i = 5;

4. Declaration of variables: the careful person may have found out, in the above two lines of code we defined the variable i, but there is no type description before. In Python, we don't need to declare a variable to define it.

 Having said so much, we felt no meaning at all, the following section of code:

1Number = 252Times = 33 4  whileTimes! =0:5s ="Enter A integer (you just has%d times):"%(Times)6Guess =Int (input (s))7     ifNumber = =guess:8         Print("You win!")9         Print("(but you don ' t win any prizes!)")Ten          Break One     elifNumber >guess: ATimes-=1 -         Print("You input is lower than that! try again.") -     Else: theTimes-=1 -         Print("You input is higher than that! try again.") - ifTimes = =0: -     Print("your times is over!") +  - Print("done!")

No hurry, let's analyze it slowly. Two global variables, number and times are defined. Although number does not use the keyword global modifier, it is still a global variable. Because it affirms in the head. This is similar to C. Next is a while loop, notice its format: whileexpression: Next Enter the loop body, first define a local variable s and assign the value, because to prompt the user to the remaining number of times, so you need to connect the integer variable and character, use% in the character D indicates that the format outputs an integer, the number printed is the times in the next% (times), and if there are multiple numbers that need to be printed out, use commas to separate them like this (Var1,var2 ...), then use the input function to display our s on the screen, and receive input from the user, because the input is a string, so use int to transform, and finally assign the value to the Guess variable. Then we use the IF statement to make judgments, the IF statement is the same format as the whilestatement, do not forget to have a colon after the Expression Express (:), finally exit the loop, determine whether the times is equal to zero, and choose whether to print. This is a small program. The results of the operation are as follows:

One might wonder which statements in the above program are in the while loop, which are outside the loop, which are in the if, and which are not if, and what is highlighted here is that in c,java,c++ we all use curly braces {} To make judgments, In Python, we use indentation (blank or tab). Indentation is used in Python to determine the hierarchy of logical rows, meaning that statements of the same level must have the same indentation, and each set of such statements is called a block. on top, line 4th is the start of the while loop, and the 16th line is the end of the while loop, and the 7th line is the start of the IF statement, and the 10th line is the end of the IF statement. In fact, in Python, we use indentation instead of curly braces {} in languages such as C,java.

This is the knowledge of Python that I know today. More superficial, I hope you bo friends a lot of advice! Thank you.

Python notes (i)

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.