吐槽:由于作业实在太恶心,觉得其实也没有什么值得写的通常,所以我把以前的个别删了。既然是学知识,那不如做个笔记总结。。之所以写一篇是因为确实不多,主要我觉得值得看的也就代码风格吧。
正文:
1,Week1:Python基础与代码风格
1)Basic elements of Python
Below is a list of the data types in Python with which you should be familiar.
- Primitive data types - integers (int), floating point numbers (float), strings (str), Booleans (bool),
- Built-in composite data types - lists (list), tuples (tuple), dictionaries (dict), sets (set),
- User-defined data types - objects created via a class definition.
You should also be familiar with creating various types expressions (arithmetic, Boolean, and string) using both built-in constants and variables and capable of effectively using statements of the following types:
- Simple statements - assignment statements (=), print statements (print), return statements (return), import statements (import), global statements (global), pass statements (pass),
- Compound statement - conditional statements (if, elif, else), function definitions (def), for loops (for), while loops (while), class definitions (class).
2)Guidelines for Coding Style
Documentation
Documentation strings ("docstrings") are an integral part of the Python language. They need to be in the following places:
- At the top of each file describing the purpose of the module.
- Below each class definition describing the purpose of the class.
- Below each function definition describing the purpose of the function.
Docstrings describe what is being done in a module, class, method, or function, not how it is being done. Except in rare cases where the how is part of the contract (i.e., binary search, so you know it runs in time log(n)). A docstring for a function should explain the arguments, what the function does, and what the function returns. This sample file demonstrates the use of docstrings. Note that the __init__ methods of classes generally do not have docstrings because their purpose is obvious: to initialize the object. You may want to have one, though, to describe the arguments.
These docstrings are treated specially in Python, as they allow the system to automatically give you documentation for modules, classes, functions, and methods. At the command prompt, you can type help(...), and it will return the docstring for whatever the argument you passed to help is. (Note that CodeSkulptor does not provide a command prompt, so you cannot use help in CodeSkulptor.)
文档字符串描述正在做什么,它的三个用