Python之路:变量与打印


原文来自我的独立blog: http://www.yuanyong.org/blog/python/python-variable-print


我知道我写的一些代码至今仍然在运行,我觉得这是一个令人欣慰的贡献。

动态类型定义语言,因此它不需要像c一样需要在使用前使用显示数据类型声明,下面来验证python动态类型属性:

1 # int test
2 int_test=5
3 type(int_test)          # Result: <type 'int'>
4 # float test
5 float_test=24
6 type(float_test)        # Result: <type 'float'>
7 # string test
8 str_test="willard"
9 type(str_test)          # Result: <type 'str'>
10 # list test
11 alist=[1,2,3]
12 type(alist)             # Result: <type 'list'>
13 # tuple(元组) test
14 atuple=(2,4,'willard',3.)
15 type(atuple)            # Result: <type 'tuple'>
16 type(atuple[0])         # Result: <type 'int'>
17 type(atuple[2])         # Result: <type 'str'>
18 type(atuple[4])         # Result: <type 'float'>
19 # dict test
20 adict={'name':"willard",'language':"python",'age':18}
21 type(adict)             # Result: <type 'dict'>
22 type(adict['name'])     # Result: <type 'str'>
23 type(adict['age'])      # Result: <type 'int'>
24 # file test
25 file_ex= open('hellopython''w')   #打开一个名为hellopython的文件,往里面写入数据流,file_ex是文件句柄
26 type(file_ex)           # Result: <type 'file' >
27 file_ex.write('hello python\n')
28 file_ex.close

先就到这里,困了,午休~

人生苦短,我用python~


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值