Python Basics (i)

Source: Internet
Author: User
Tags svn client svn update

Written in front: this time the determination to learn python, the goal is the lowest: at least can independently complete a self-blogging site, a h5app, and very skilled use of pandas,numpy and other commonly used data analysis tools, hope not to give up, refueling!

Python Basics (i):

Python was born early, but the previous years in the domestic has been tepid, the momentum is not as good as java,php, in the software outsourcing industry in the heyday of the development of Python as a language B/S architecture system. These years, because of the fiery automation operations, python because of its low development difficulty, full-featured, gradually in the operation of the ring popular. Although in my opinion, most of the automation operations do not need any language assistance outside the shell, but with the increasing importance of operations in the country, because Python in advanced features than the shell still has advantages, python in the operation of the function is also more and more high proportion.

Python categories:

Because Python is a popular free-to-interpret open-source language, a lot of Python mania is in order to make Python more powerful (!). ) derivative developed a number of new interpreters:

CPython: This is the most common version of Python, developed in C language. Jython: Developed with Java. It is obvious that Jython can invoke the various libraries of Java directly, and is very friendly to Java development. PyPy: Using Python development, it is said that pypy efficiency is much higher than cpython, it should be the realization of the multi-threaded Python function bar (guess haha). The benefit of the ironpython:c# version is that you can call the C # development library.

Learn python must start from CPython, we first deploy the environment, according to the corresponding operating system from https://www.centos.org/download the version you need to install. Isn't it convenient? (I learned that Python starts from 3.5)

Once the installation is complete, we can begin:

Create a new file named ***.py and enter edit mode:

Enter the following two lines

#!/usr/bin/python3 <----Define the interpreter path, fill in the actual path according to the system
Print (' Hello! ') #<----Print method for outputting strings to the screen.

Then double-click on the terminal or CMD or desktop to run:

Hello!

The first Python program executed successfully, is not actually very simple! Ha ha

Maybe some of the Windows environment classmate (I am MAC) here encountered a problem, it seems that the output of garbled, here due to the problem of encoding format, CMD program The default output encoding is GBK, and 3.5 The default output encoding is Utf-8, there are two solutions: Modify the output code of CMD to Utf-8, or to the Python output code transcoding operation, converted to GBK, but this is not described in detail.

Let's Change the code:

#!/usr/bin/python3
Output = input (' Try input character: ') #<-----Input method is used to receive keyboard input.
Print (output)

The following results are performed:

Try input characters: 123
123

The program already has the basic input and output function, does it look like a look? But it's still a worthless procedure.

Let's change it and make it look like a little bit of a program:

#!/usr/bin/python3
usr = input (' Try to enter character: ')
PWD = input (' Try to enter character: ')

If usr = ' jizast ' and pwd ' 123 ': print (' Validate through ')
else print (' validation failed ')

The program is still simple, but adds a judgment statement to him: if ... else ..... Let the program finally look a little smart.

But once the validation fails, it's too hard to get out of the program, and every time the verification is performed, we're optimizing:

#!/usr/bin/python3
Whlie True:
usr = input (' Try to enter character: ')
PWD = input (' Try to enter character: ')
If usr = ' jizast ' and pwd ' 123 ': print (' Validate through ')
else print (' validation failed ')

This procedure does not have to open frequently, because added a loop statement: while ..., but there is still a problem: if you are a hacker, you want to crack the password by guessing, that gives you an unlimited number of attempts is very dangerous, we modified:

CS = 3
While CS > 0:
Username = input ("Please enter user name:")
Password = input ("Please enter password:")
If username = = ' Alex ' and password = = ' 123 ':
Print ("Login successful!")
Break
Else
CS-= 1
If CS ==0:
Print (' Error more than three times, program automatically exits. ')
Break
Print ("Login failed!" Please check your username or password! You also have "+ str (CS) +" chance ")

Is it a little messy to add too many features at once? Let's take a slow look.

CS = 3 #<------Declares a variable of CS and assigns a value.

If you have learned C come over the classmate, certainly do not like this, why a variable is not required to declare the variable type before? But that's the benefit of Python, you don't need to do this:

When you assign a number to him, he is the int type, and when you assign the string to him, he is the STR type, and in fact Python's common data types are as follows:

Data type Example
Digital 123, 3.1, 3+4j, Decimal
String ' abc ', ' abc ' d ', B ' asd\xc '
List [1, ' 2 ', [' Three ', 4]]
Meta-group (1, ' 2 ', 3)
Dictionary {' name ': ' Jizast ', ' looks ': ' Dashing '}
Special types None, True, False, custom class

Here CS is a numeric type that plays an identifier in the program and then knows what it's for:

While CS > 0:

This is a looping statement that executes the statement under the while module repeatedly and exits under specified conditions.

Here are the following common loop statements:

The while loop is the most common iteration structure in Python, which is practically in almost all programming languages, and is always executed while the while test is true.

    If username = = ' Alex ' and password = = ' 123 ':
Print ("Login successful!")
Break

There is a break statement in the If module, which is used to exit the while loop, that is, while in addition to the top test exit mode, you can also exit the program through the break statement inside the module.

If is the most commonly used judgment statement in Python (also for all languages) in the format If....elif.....else ...., i.e.:

If A is true: Perform 1

Elif B is true: Execution 2

Else A is false: execution 3

This if in the program is actually a judgment function, if the user name and password matching is successful login, and no longer perform cyclic validation.

    Else
CS-= 1
If CS ==0:
Print (' Error more than three times, program automatically exits. ')
Break
Print ("Login failed!" Please check your username or password! You also have "+ str (CS) +" chance ")

This is the process of validating the failure:

If the user name password verification fails, this CS variable minus one, that is, the number of attempts minus one time, and print the error message. When cs = 0 o'clock, the number of attempts is exhausted and the program ends automatically.

Summary of the program function: After the user entered the user name password, if the correct landing, if the information is wrong, you can try to re-enter, there are three opportunities. If more than three times it exits automatically.

Is that like it's going to happen? Seems to have implemented a simple user login function!

But now learn so much, later can achieve more complex features Oh!

Attached: The SVN command use tutorial

Because the Mac does not have a part of the SVN client, so bitter I can only take precedence over the command line tool SVN, but after learning to find this is as powerful as the client, for operations, command line client tool is always stronger than the desktop client tools, you know.

First we create an SVN workspace locally, for example, called stu123.

Now let's start by trying to initialize the workspace:

#SVN import/users/mouibayashi/documents/stu123 svn://svn server address --username= user name--password= password-M " Action Note "

Once the initialization is complete, we can create the file.

#svn add-m "Create a sync file"

If you are manually copying to a local workspace, you will need to add it to the remote directory by using the Add command

After you have modified the contents of the file, you need to submit

#svn commit-m "Commit Changes"

If the SVN remote space file sends changes, then you need to update to local space

#svn Update (Optional: Partial file)

This is what you need for the time being, then use advanced features later.

Python Basics (i)

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.