用python写一个hello world程序

(1) 建一个hello.py
[hadoop@slave1 桌面]$ vi hello.py 

点击(此处)折叠或打开

  1. print("Hello World!")
(2)通过"python *.py"运行python脚本
[hadoop@slave1 桌面]$ python hello.py 
Hello World!
或者:

点击(此处)折叠或打开

  1. $ python
  2. Python 2.6.6 (r266:84292, Feb 21 2013, 23:54:59)
  3. [GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
  4. Type "help", "copyright", "credits" or "license" for more information.
  5. >>> print "hello world"
  6. hello world
(3)接受用户输入
[hadoop@slave1 桌面]$ vi hello.py 

点击(此处)折叠或打开

  1. print("Hello World!")
  2. x=input("x:")
  3. y=input("y:")
  4. print(x*y)
  5. print("I will begin to learn python,come on !")
(4)执行
[hadoop@slave1 桌面]$ python hello.py 
Hello World!
x:125
y:2
250
I will begin to learn python,come on !
请使用浏览器的分享功能分享到微信等