Concise Python Tutorial--Learning record

Source: Internet
Author: User
Tags natural string

Note that a return statement with no return value is equivalent to return none. None is a special in python that means nothing
Type. For example, if a variable has a value of none, you can indicate that it has no value.
Unless you provide your own return statement, each function contains a return none statement at the end. By running print
SomeFunction (), you can understand this, the function someFunction does not use the return statement, as follows:
Def someFunction ():
Pass
The pass statement represents an empty block of statements in Python.

The first number in the slice operator (preceded by a colon) indicates where the slice begins, and the second number (after the colon) represents the slice
Where to end. If you do not specify the first number, Python starts from the beginning of the sequence. If you do not specify a second number, the
Python stops at the end of the sequence. Note that the returned sequence starts at the start position and ends just before the end position. That
The start position is contained in the sequence slice, and the end position is excluded from the slice.

This way, Shoplist[1:3] returns starting at position 1, including position 2, but stopping a sequence slice at position 3, so the return
Back a slice containing two items. Similarly, shoplist[:] Returns a copy of the entire sequence.
You can make slices with negative numbers. Negative numbers are used at the beginning of the end of the sequence. For example, Shoplist[:-1] will return except for the last
A sequence slice that contains all items outside an item.
Use the Python interpreter to interactively try out different slices of the specified combination, i.e. you can see the results immediately at the prompt. Sequence of
The magic is that you can access tuples, lists, and strings in the same way.

The index can also be negative, in which case the position is calculated from the end of the sequence. Therefore, Shoplist[-1] says
The last element of the sequence and Shoplist[-2] The penultimate item of the crawl sequence.

We use the addition operator to concatenate strings, that is, two strings are concatenated together to return a new string.

The zip command has some options and parameters. The-Q option is used to indicate that the zip command works quietly. The-r option indicates that the ZIP command is recursive to the directory
To work, that is, it includes subdirectories and files within subdirectories. Two options can be combined into an abbreviated form-QR. Option after
The name of the ZIP archive that you want to create, and then the list of files and directories to be backed up. We use the already learned
The string join method converts the source list to a string.

We use the Os.system function to run the command, using this function as if the system

Comments to Windows users
You can set the source list and the target directory to any file and directory name, but you have to be careful in Windows.
The problem is that Windows uses a backslash (\) as the directory delimiter, while Python represents the escape character with a backslash!
So, you have to use the escape character to represent the backslash itself or use a natural string. For example, using ' c:\\documents ' or
R ' C:\Documents ' instead of ' C:\Documents '-you're using an unidentified escape character \d!

Most of the two programs are the same. Part of the change is the use of the Os.exists function to verify if there are any in the primary backup directory
The directory with the current date as the name. If not, we use the Os.mkdir function to create the.
Note the use of the OS.SEP variable-this will give you a directory delimiter based on your operating system, which is under Linux, Unix
Is '/', under Windows it is ' \ \ ', while in Mac OS it is ': '. Using os.sep rather than using characters directly will make our
The procedures are portable and can work under these systems.

Important
The process of creating this backup script is the recommended method for writing programs-for analysis and design. At the beginning, implement a simple
A single version. Test and debug it. Use it to make sure it works as expected. Add any extra you want.
and repeat this write-test-use cycle as needed. Remember, "Software is grown, not built."
of ".

Comments to the c++/java/c# programmer
Self in Python is equivalent to the self pointer in C + + and the This reference in Java, C #.
You must be wondering how Python assigns to self and why you don't need to assign a value to it. Give an example to make this clear
Clear Suppose you have a class called MyClass and an instance of this class MyObject. When you call this object's method
Myobject.method (Arg1, arg2), this is automatically converted from Python to Myclass.method (MyObject, Arg1,
ARG2)-This is the principle of self.
This also means that if you have a method that does not require parameters, you still have to define a self parameter for this method.

Comments to the c++/java/c# programmer
The __init__ method is similar to constructor in C + +, C #, and Java.

Comments to the c++/java/c# programmer
All of the class members (including data members) in Python are public and all methods are valid.
There is only one exception: if you use a data member name with a double-underscore prefix such as __privatevar,python name
The management system effectively takes it as a private variable.
This makes it a rule that if a variable is only meant to be used in a class or object, it should be prefixed with a single underscore. While the other
The name will be public and can be used by other classes/objects. Remember this is just a convention, not what Python requires
(different from the double underscore prefix).
Similarly, note that the __del__ method is similar to the concept of destructor.

Concise Python Tutorial--Learning record

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.