python-1 python基础知识
python第一课代码笔记
hello world
[root@heartbeat-data-1 python]# vim hello1.py #!/usr/bin/env python print ('hello world!') [root@heartbeat-data-1 python]# python hello1.py hello world! 注意
#!/usr/bin/python是告诉操作系统执行这个脚本的时候,调用/usr/bin下的python解释器;#!/usr/bin/env python这种用法是为了防止操作系统用户没有将python装在默认的/usr/bin路径里。当系统看到这一行的时候,首先会到env设置里查找python的安装路径,再调用对应路径下的解释器程序完成操作。#!/usr/bin/python相当于写死了python路径;#!/usr/bin/env python会去环境设置寻找python目录,推荐这种写法
[root@heartbeat-data-1 python]# vim hello2.py def main(): print("hello") main() IndentationError: expected an indented block 缩进错误 [root@heartbeat-data-1 python]# vim hello2.py def main(): print("hello") main()
变量
[root@heartbeat-data-1 python]# vim plus.py x = 2 y = 3 print (x + y) [root@heartbeat-data-1 python]# python plus.py 5 [root@localhost python]# vim plus.py def main(): x = 2 y = 4 print(x + y) main() # python plus.py6 大写的一般是常量,小写的是变量 [root@heartbeat-data-1 python]# vim test.py x = 2 y = 3 z = x x = 5 print ('Z:',z) print ('X:',x) [root@heartbeat-data-1 python]# python test.py Z: 2 X: 5 [root@heartbeat-data-1 python]# vim test1.py a = 'ABC' b = a a = 'XYZ' print(b) print(a) [root@heartbeat-data-1 python]# python test1.py ABC XYZ 单行注释:#,多行注释:’’’ 三个引号 #print ‘ddd’ [root@localhost python]# vim zhushi.py print''' print 'ddd' print 'ddd' print 'ddd' ------------------'''
[root@localhost python]# python zhushi.py
print 'ddd'
print 'ddd'
print 'ddd'
------------------
相关推荐
huavhuahua 2020-11-20
weiiron 2020-11-16
cakecc00 2020-11-15
千锋 2020-11-15
JakobHu 2020-11-14
guangcheng 2020-11-13
xirongxudlut 2020-11-10
solarLan 2020-11-09
pythonxuexi 2020-11-08
文山羊 2020-11-07
susmote 2020-11-07
wuShiJingZuo 2020-11-05
Pythonjeff远 2020-11-06
jacktangj 2020-11-04
lousir 2020-11-04
Noneyes 2020-11-10
ailxxiaoli 2020-11-16
chensen 2020-11-14
Nostalgiachild 2020-11-13