【笔记】Part1:Python基础与代码风格 (Principles of Computing)

吐槽:由于作业实在太恶心,觉得其实也没有什么值得写的通常,所以我把以前的个别删了。既然是学知识,那不如做个笔记总结。。之所以写一篇是因为确实不多,主要我觉得值得看的也就代码风格吧。

正文:

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.)

文档字符串描述正在做什么,它的三个用

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值