您的位置:首页 > 编程语言 > Java开发

Lecture 3 Control | CS 61A: Structure and Interpretation of Computer Programs Spring 2020

2020-04-21 22:12 471 查看

Print and None

None Indicates that Nothing is Returned,The special value None represents nothing in Python

A function that does not explicitly return a value will return None

Careful: None is not displayed by the interpreter as the value of an expression

Pure Functions & Non-Pure Functions

Nested Expressions with Print

Life Cycle of a User-Defined Function

Names Have Different Meanings in Different Environments

Statement

While Statements

Operators

it comes to division, Python provides two infix operators: / and //. The former is normal division, so that it results in a floating point, or decimal value, even if the divisor evenly divides the dividend:

>>> 5 / 4
1.25
>>> 8 / 4
2.0

The // operator, on the other hand, rounds the result down to an integer:

>>> 5 // 4
1
>>> -5 // 4
-2

These two operators are shorthand for the truediv and floordiv functions.

>>> from operator import truediv, floordiv
>>> truediv(5, 4)
1.25
>>> floordiv(5, 4)
1
  • 点赞
  • 收藏
  • 分享
  • 文章举报
yaoxinJJJ 发布了20 篇原创文章 · 获赞 1 · 访问量 675 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐