最近网上下了一本书“Python核心编程”,看了下,感觉这本书不错,随便看了下,准备学习点新玩意。。。
        本文所讲的都是在RHEL5.4的版本下作的实验,因为Python可以在好多系统下面运行,也是可以跨平台的运行,由于是用C写的,能很好的和C/C++一起结合,嘿嘿,居然也可以调用JAVA,呵呵,果然是很强悍啊。
         先看看你的系统里面有没有安装Python,因为有好对系统都是自带的。。。
 
[root@localhost python]# rpm -qa | grep python
python-elementtree-1.2.6-5
python-numeric-23.7-2.2.2
notify-python-0.1.0-3.fc6
gnome-python2-canvas-2.16.0-1.fc6
gnome-python2-gtkhtml2-2.14.2-6.el5
python-2.4.3-27.el5
libxml2-python-2.6.26-2.1.2.8
audit-libs-python-1.7.13-2.el5
python-sqlite-1.1.7-1.2.1
gamin-python-0.1.7-8.el5
python-ldap-2.2.0-2.1
python-urlgrabber-3.1.0-5.el5
dbus-python-0.70-7.el5
gnome-python2-2.16.0-1.fc6
gnome-python2-gconf-2.16.0-1.fc6
gnome-python2-gnomevfs-2.16.0-1.fc6
gnome-python2-extras-2.14.2-6.el5
libselinux-python-1.33.4-5.5.el5
python-iniparse-0.2.3-4.el5
rpm-python-4.4.2.3-18.el5
gnome-python2-bonobo-2.16.0-1.fc6
 
      嘿嘿,我的系统已经装了,如果没有的话,去找下RPM包,自己安装下吧,
     Python运行的方式有好多种,我这里只说最简单的一种
[root@localhost python]#
[root@localhost python]# python                                                   #终端直接运行python
Python 2.4.3 (#1, Jun 11 2009, 14:09:58)                                           #可以看到系统信息
[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print "hello world!"                                                       #Python版的HELLO WORLD
hello world!                                                                            #打印出来Hello world
>>> myString="Hello Python !"                                       #给变量赋值
>>> print myString                                                            #打印变量值
Hello Python !
>>> myString                                                                   #还可以这样写
'Hello Python !'
>>> _                                                                              #Python里面_(下划线)的特殊用处
'Hello Python !'                     
>>>
        由于这里是第一次只是介绍下pytho,所以不讲语法,只是举下几个例子
[root@localhost python]# cat input.py                                   #获取键盘输入例子代码
#!/usr/bin/python2.4
name=raw_input("Enter login name:")
print "Your login name is :",name
num=raw_input("Enter a number:")
print "Doubling your number is :%d" % (int(num)*2)
 
[root@localhost python]# ./input.py
Enter login name:python                                           #输入用户名
Your login name is : python                                     #打印
Enter a number:1024                                                   #输入一个数字
Doubling your number is :2048                              #打印
[root@localhost python]#
 
[root@localhost python]# cat print.py                         ##处理字符代码
#!/usr/bin/python2.4
myString ="hello world!"
print "%s is number %d!" % ("Python",1)
[root@localhost python]#
[root@localhost python]# ./print.py                               #运行程序
Python is number 1!
[root@localhost python]#

       相信大家都能看懂上面的例子,好了,今天第一次接触就到这里了,以后会开始我们的Python学习之路。。。