Python——python了解
来源:互联网 发布:微表情测试软件 编辑:程序博客网 时间:2024/06/08 06:16
python
优点
简单、易学 、免费/开源 、自动内存管理 、可以移植 、解释性 、面向对象 、可扩展 、丰富的第三方库
缺点
速度慢、强制缩进、单行语句
[root@localhost ~]# python -V ##查看安装的python版本
Python 2.7.5
[root@localhost ~]# python ##交互式使用python
Python 2.7.5 (default, Feb 11 2014, 07:46:25) [GCC 4.8.2 20140120 (Red Hat 4.8.2-13)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> print "hello python"hello python>>> print hello python File "<stdin>", line 1 print hello python ^SyntaxError: invalid syntax>>> a = 1>>> print a1>>> print "你好"你好>>> exit () ##退出
[root@localhost ~]# cd /mnt/
[root@localhost mnt]# ls
[root@localhost mnt]# vim hello.sh ##编写一个shall脚本
#!/bin/bashecho hello
[root@localhost mnt]# chmod +x hello.sh
[root@localhost mnt]# ./hello.sh
hello
[root@localhost mnt]# cp hello.sh /bin/
[root@localhost mnt]# hello.sh
hello
[root@localhost mnt]# which python ##查看python位置
/usr/bin/python
[root@localhost mnt]# vim hello.py ##编写一个python脚本
#!/usr/bin/pythonprint "hello"
[root@localhost mnt]# python hello.py
hello
[root@localhost mnt]# chmod +x hello.py
[root@localhost mnt]# ./hello.py
hello
[root@localhost mnt]# cp hello.py /bin/
[root@localhost mnt]# hello.py
hello
[root@localhost mnt]# vim hello.py ##python写入中文方法
#!/usr/bin/python#!/ coding: utf-8print "hello"print "你好"
[root@localhost mnt]# python hello.py
hello
你好
[root@localhost mnt]# ipython ##python解释器的一种,进入python后可以用tab补齐
Python 2.7.5 (default, Feb 11 2014, 07:46:25)
Type “copyright”, “credits” or “license” for more information.
IPython 3.2.1 – An enhanced Interactive Python.
? -> Introduction and overview of IPython’s features.
%quickref -> Quick reference.
help -> Python’s own help system.
object? -> Details about ‘object’, use ‘object??’ for extra details.
In [1]: hi = “hello”
In [2]: h
%%html %history hash help hi
%hist hasattr hello.py hex
In [2]: hi
Out[2]: ‘hello’