python字符串变量数值_Python语言的类型 变量 数值和字符串

本文主要向大家介绍了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_compilepy_compile.compile('hello.py')>[root@lyon-01 python]# vim 2.py>#! /usr/bin/python>import  py_compilepy_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(shellow 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/pythonnum1 = input("please a number: ")num2 = input("please a number: ")print num1 + num2print num1 - num2print num1  num2print num1 / num2[root@lyon-01 python]# python 3.py please a number: 5please a number: 382151[root@lyon-01 python]# vim 3.py#! /usr/bin/pythonnum1 = 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, num1num2)print "%s / %s = %s" % (num1, num2, num1/num2)[root@lyon-01 python]# python 3.py please a number: 7please a number: 37 + 3 = 107 - 3 = 47  3 = 217 / 3 = 2python的数据类型案例 123和‘123’一样吗?123 代表数值‘123’代表字符串还有   列表  元祖  字典数值类型 长整型In [9]: a = 12999999999999999999999In [10]: aOut[10]: 12999999999999999999999LIn [11]: type (a)Out[11]: long也可以把小的数值长整型In [12]: a = 100lIn [13]: type (a)Out[13]: long浮点型   例如 0.0 12.0 -18.8 3e+7 复数型 换行符In [23]: a = "hello\nworld"In [24]: print a helloworld

以上就介绍了Python的相关知识,希望对Python有兴趣的朋友有所帮助。了解更多内容,请关注职坐标编程语言Python频道!

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值