My Python learning Notes

Source: Internet
Author: User

1. Module format

#!/usr/bin/env python
#-*-Coding:utf-8-*-
...
...
...
If __name__== ' __main__ ':
Main ()

2.

A simple summary of Functools.partial's function is to fix certain parameters of a function (that is, to set a default value) and return a new function, which is simpler to call the new function.

3.
When a function has too many arguments and needs to be simplified, use functools.partial to create a new function that can fix some of the parameters of the original function, making it easier to invoke.

4.
In general, third-party libraries will be registered in the official Python pypi.python.org website, to install a third-party library, you must first know the name of the library, you can search on the official website or pypi, such as the name of the Python Imaging library called PiL
, so the command to install the Python Imaging Library is:
Pip Install PIL
Run
Pip install PIL--allow-external PIL--allow-unverified PIL
command, the prompt said not to install C + +, from the prompt to download the URL to install C + +, then execute the above command is successful successfully installed PIL

5.
It is important to note that in Python, the variable name is similar to __xxx__, which starts with a double underscore, and ends with a double underscore, which is a special variable that can be accessed directly, not a private variable, so you can't use __name__
, such as the __score__ variable name.

6.
There are times when you see an instance variable name that starts with an underscore, such as _name, which can be accessed outside of an instance variable, but, in accordance with the rules, when you see such a variable, it means, "although I can be accessed
, but please treat me as a private variable and don't feel free to access ".

7.
Note that one type is called Typetype, and the types themselves are typetype, such as:
>>> type (int) ==type (str) ==types. Typetype
True

8. For an example, feel the effect of os.path.join ()
>>> path= '. '
>>> new_path= ' ZK '
>>> jon = Os.path.join (Path,new_path)
>>> Jon
'. \\zk '

9. Common formats
Try
Import Cpickle as Pickle
Except Importerror:
Import Pickle

10.
We can steal a lazy, turn an instance of any class into dict:
Import JSON
Class Student (object):
def __init__ (self, name, age, score):
Self.name = Name
Self.age = Age
Self.score = Score
s = Student (' Bob ', 20, 88)
Print (Json.dumps (s, Default=lambda obj:obj.__dict__))
Because an instance of class usually has a __dict__ property, it is a dict that stores instance variables. There are a few exceptions, such as defining the class of __slots__.

My Python learning Notes

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.