《Python for Beginners》学习笔记(1)

《Python for Beginners》为LearnStreet上的Python入门课程。课程网页设计得很友好,可以边学边练。作为Python的初学者,如果有C语言基础,理解起来也比较容易。该笔记将重点记录Python与C语言不同的语法和编程方法。

Lesson 2 Variables, Numbers and Booleans 

学习笔记:

1.关键字(保留字):and, as, assert, break, class, continue, def, del, elif, else, except, exec, finally, for, from, global, if, import, in, is, lambda, not, or, pass, print, raise, return, try, while, with, yield.

2.两种主要数据类型:整型(int)和浮点型(float)

数据类型转换:
int(x): 将浮点型转换为整型
float(x): 将整型转换为浮点型

查看变量的数据类型:type(x)

3.布尔值:True or False

4. 比较运算符
== equal to
<   strictly less than
>   strictly greater than
<= less than or equal to
>= greater than or equal to
!    negates any of the above (e.g., != is not equal) (不是很清楚怎么用)

5. 算术运算符
+ add
- subtract
* multiply
/ divide
** power (5**2 = 25, or 5 to the second power) (与C语言不同)
// floor division (与C语言不同)
% modulus

原文地址:https://www.cnblogs.com/geekham/p/2936947.html