按照編程傳統,先來輸出一個"Hello,World!",過程相當簡單,直接上命令和結果:
>>> print "Hello,World!" Hello,World!
在百度百科上提到“……,在國外用Python做科學計算的研究機構日益增多,……”,接下來搞幾個我兒子學習的算數題試試:
>>> 10+3 13 >>> 12+18 30
我在計算器上驗證了一下,10+3=13沒錯,12+16=28纔對呢,這是怎麼回事!!!
在實際應用當中應該把輸入存入文件,再次使用的時候直接用就行了,不會像上面都說不清是記憶錯誤還是輸入錯誤的問題了。
接下來把 print "Hello,World!"存入hello.py
[root@Python-Test pythontest]# cat >> hello.py <<EOF > print "Hello,world!" > EOF [root@Python-Test pythontest]# ll total 4 -rw-r--r--. 1 root root 21 Feb 6 13:09 hello.py
[root@Python-Test pythontest]# chmod +x hello.py [root@Python-Test pythontest]# ll total 4 -rwxr-xr-x. 1 root root 21 Feb 6 13:09 hello.py
[root@Python-Test pythontest]# ./hello.py
./hello.py: line 1: print: command not found
[root@Python-Test pythontest]# python hello.py Hello,world!
爲啥直接不能執行呢?在程序中第一行位置加入#!/usr/bin/env python
[root@Python-Test pythontest]# cat hello.py #!/usr/bin/env python print "Hello,world!" [root@Python-Test pythontest]# ./hello.py Hello,world!
先到這裏了,明天繼續