Note of "Learn Python the HardWay"

来源:互联网 发布:先锋软件学院 编辑:程序博客网 时间:2024/05/16 12:36

1.SetUp &Environment [Important before Staring!]

        Just use the Notepad++ to edit it, and use the PowerShell(Windows) to run it.-------For a better learning of Python!

2.Print(Output)

      This can be very basic. Just be skillful at "%s, %d, %r".

      Pay attention to the difference of "%s" and "%r"----------  %r is usually used in debugging, it just prints out the raw representation of what you typed.

      %d for integer, %f for float........

3.Input

       Two ways------raw_input() [just don't use input()] orargv

4.Reading & Writing of Files

 

  • close -- Closes the file. Like File->Save.. in your editor.
  • read -- Reads the contents of the file. You can assign the result to a variable.
  • readline -- Reads just one line of a text file.
  • truncate -- Empties the file. Watch out if you care about the file.       should in mode['w']
  • write('stuff') -- Writes "stuff" to the file.    should in mode['w']

5.About Functions

This can be easy because the Function in Python is almost just like it in other languages like Java or C++...

         NoNoNo...Pay attention to use the keyword "def"

6.Reading more codes

Once upon you have know the basic usage, you need to read some codes-----in github or something else.

For example, I'm reading "geekcomputers" from github.com! See you soon. Only to find it to easy(?Nope,,,but it's structure to easy = =?)

Then I find the "kennethreitz/requests" in github. It is a HTTP library written in Python and based on urllib.




Appendix:

1. To get a brief introduction ---------Eg: 

Windows下输入:python -m pydoc raw_input     [查看函数介绍]


0 0
原创粉丝点击