kllhi 发表于 2016-1-26 08:43:31

python入门学习之变量篇

1.理解布尔值

一种数据类型。

简单来说,正如你家里的电灯有开关两种状态一样,布尔值
同样也有两个值,即为True和False。
你可以使用变量来存储布尔数据。

1
2
a = True
b = False




2.实战
以下为网站给出的任务:

1
2
3
4
5
Set the following variables to the corresponding values:

    my_int to the value 7
    my_float to the value 1.23
    my_bool to the value True




完成如下:

1
2
3
4
5
# Set the variables to the values listed in the instructions!
my_int = 7
my_float = 1.23
my_bool = True
print 'The three variables are as follows ',my_int,my_float,my_bool




输出结果:

3.总结
1)变量前后都要保持一个空格。
2)变量名之间用下划线_隔开,当然也可以使用驼峰式(VarName)。
3)True与False的第一个字母要大写。

BTW,这种学习风格有点像打游戏冲关式的,让人沉迷于其中。
页: [1]
查看完整版本: python入门学习之变量篇