一、python的文件类型与变量

源码就是py文件,可以直接执行和访问:

cat 1.py
print ("hello word!")
 
python 1.py
hello word!

编译成pyc文件
.pyc 文件(字节代码)

vim 11.py
#!/usr/bin/python
import py_compile
py_compile.compile('11.py')
print ("hello word!")

此时会生成一个11.pyc文件,并且是个二进制文件,不能直接访问,但是能运行,

python 1.pyc

hello word!

其中11.py代表当前目录下的11.py文件,将11.py改成二进制文件并且后缀为11.pyc
.pyo文件(优化代码)

[root@geenk01 py]# python -O -m py_compile 11.py
[root@geenk01 py]# ls
11.py  11.pyc  11.pyo  22.py

查看变量文件类型,用type,id代表内存地址。

>>> a=456
>>> id(a)
30152544
>>> type(a)
<type 'int'> 

算术运算符

+ - * / // %  **
其中的// 表示整除,只取整数。
% 表示只取余数
** 表示乘方,2**3  表示二的三次方

关系运算符

> < >= <=  == !=
a=a+2 等于a+=2

逻辑运算符

and 逻辑与: True and False
or 逻辑或:False or True
not 逻辑非:not True

第一个交互运算脚本:

vim a.py
#!/usr/bin/python

a=input("please input num: ")
b=input("please input num2: ")

print ("%s + %s = %s" %(a,b,a+b))

[root@jie py]# python 1.py
please input num: 1
please input num2: 2
1 + 2 = 3

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值