python字符串变量数值_python的类型 变量 数值和字符串

文件类型一

源代码 -Python源代码文件以“py”为扩展名,由Python程序解释,不需要编译 >>[root@lyon-01 ~]# mkdir python [root@lyon-01 ~]# cd python/ [root@lyon-01 python]# vim 1.py //写一个代码

>>#! /usr/bin/python

>>print 'hellow world'

>>[root@lyon-01 python]# python 1.py //执行 hellow world

文件类型二 字节代码 -Python源代码文件经编译后,生成的扩展名为“pyc”的文件 -编译方法: >>import py_compile py_compile.compile('hello.py')

>>[root@lyon-01 python]# vim 2.py

>>#! /usr/bin/python

>>import py_compile py_compile.compile('./1.py') [root@lyon-01 python]# python 2.py [root@lyon-01 python]# ls 1.py 1.pyc 2.py [root@lyon-01 python]# file 1.pyc 1.pyc: python 2.7 byte-compiled [root@lyon-01 python]# cat 1.py #! /usr/bin/python

>>print 'hellow world' [root@lyon-01 python]# cat 1.pyc

»顁@s dGHdS(s hellow worldN((((s./1.pys //二进制的乱码文件 [root@lyon-01 python]# [root@lyon-01 python]# python 1.pyc //用Python查看 hellow world

[root@lyon-01 python]# -优化代码 -经过优化的源码文件,扩展名为“pyo” -Python -O -m py_compile hello.py

>>[root@lyon-01 python]# python -O -m py_compile 1.py [root@lyon-01 python]# ls 1.py 1.pyc 1.pyo 2.py [root@lyon-01 python]# python 1.pyo

hellow world [root@lyon-01 python]#

python 的变量 --变量是计算机内存中的一块区域,变量可以存储规定范围内的值,而且值可以改变 --Python下的变量是对一个数据的引用 --变量的命名 由字母 数字 下划线组成 不能以数字开头 不可以使用关键字 --变量的赋值 是变量的声明和定义的过程 a = 1 id(a)

>>[root@lyon-01 python]# vim 3.py #! /usr/bin/python num1 = input("please a number: ") num2 = input("please a number: ") print num1 + num2 print num1 - num2 print num1 * num2 print num1 / num2 [root@lyon-01 python]# python 3.py please a number: 5 please a number: 3 8 2 15 1 [root@lyon-01 python]# vim 3.py #! /usr/bin/python num1 = input("please a number: ") num2 = input("please a number: ") print "%s + %s = %s" % (num1, num2, num1+num2) print "%s - %s = %s" % (num1, num2, num1-num2) print "%s * %s = %s" % (num1, num2, num1*num2) print "%s / %s = %s" % (num1, num2, num1/num2) [root@lyon-01 python]# python 3.py please a number: 7 please a number: 3 7 + 3 = 10 7 - 3 = 4 7 * 3 = 21 7 / 3 = 2

python的数据类型 案例 123和‘123’一样吗? 123 代表数值 ‘123’代表字符串 还有 列表 元祖 字典 数值类型 长整型 >In [9]: a = 12999999999999999999999 In [10]: a Out[10]: 12999999999999999999999L In [11]: type (a) Out[11]: long 也可以把小的数值长整型 In [12]: a = 100l In [13]: type (a) Out[13]: long

浮点型 例如 0.0 12.0 -18.8 3e+7 复数型 换行符 >In [23]: a = "hello\nworld" In [24]: print a hello world

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值