Python——python了解

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 linux2
Type "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 a
1
>>> print "你好"
你好
>>> exit () ##退出

这里写图片描述

[root@localhost ~]# cd /mnt/
[root@localhost mnt]# ls
[root@localhost mnt]# vim hello.sh ##编写一个shall脚本

#!/bin/bash
echo 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/python
print "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-8
print "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’
这里写图片描述

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值