对于Linux来说,Python一般是默认就安装了的:
[root@center-me ~]# whereis python python: /usr/bin/python /usr/bin/python2.7 /usr/lib/python2.7 /usr/lib64/python2.7 /usr/include/python2.7 /usr/share/man/man1/python.1.gz [root@center-me ~]#
你可以通过下面的命令去查看一下你系统当前的Python的版本情况:
[root@center-me ~]# python -V Python 2.7.5 [root@center-me ~]#
打印“Hello world”:
交互方式:
[root@center-me python]# python Python 2.7.5 (default, Jun 17 2014, 18:11:42) [GCC 4.8.2 20140120 (Red Hat 4.8.2-16)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> print 'hello world' hello world >>>
写到源码文件里面:
[root@center-me python]# cat hello_world.py #!/usr/bin/python print 'Hello world' [root@center-me python]# [root@center-me python]# python hello_world.py Hello world [root@center-me python]#
或者这样执行:
[root@center-me python]# ls -ltr * -rw-r--r-- 1 root root 107 Mar 3 11:03 array.py -rw-r--r-- 1 root root 38 Mar 30 14:05 hello_world.py [root@center-me python]# [root@center-me python]# chmod a+x hello_world.py [root@center-me python]# [root@center-me python]# ls -ltr * -rw-r--r-- 1 root root 107 Mar 3 11:03 array.py -rwxr-xr-x 1 root root 38 Mar 30 14:05 hello_world.py [root@center-me python]# [root@center-me python]# ./hello_world.py Hello world [root@center-me python]#
获得帮助:
[root@center-me python]# python Python 2.7.5 (default, Jun 17 2014, 18:11:42) [GCC 4.8.2 20140120 (Red Hat 4.8.2-16)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> help('print'); The ``print`` statement *********************** print_stmt ::= "print" ([expression ("," expression)* [","]] | ">>" expression [("," expression)+ [","]]) ``print`` evaluates each expression in turn and writes the resulting object to standard output (see below). If an object is not a string, it is first converted to a string using the rules for string conversions. The (resulting or original) string is then written. A space is written before each object is (converted and) written, unless the output system believes it is positioned at the beginning of a line. This is the case (1) when no characters have yet been written to standard output, (2) when the last character written to standard output is a whitespace character except ``' '``, or (3) when the last write operation on standard output was not a ``print`` statement. (In some cases it may be functional to write an empty string to standard output for this reason.) Note: Objects which act like file objects but which are not the built-in file objects often do not properly emulate this aspect of the file object's behavior, so it is best not to rely on this. A ``'\n'`` character is written at the end, unless the ``print`` statement ends with a comma. This is the only action if the statement contains just the keyword ``print``. Standard output is defined as the file object named ``stdout`` in the built-in module ``sys``. If no such object exists, or if it does not have a ``write()`` method, a ``RuntimeError`` exception is raised. ``print`` also has an extended form, defined by the second portion of the syntax described above. This form is sometimes referred to as "``print`` chevron." In this form, the first expression after the ``>>`` must evaluate to a "file-like" object, specifically an object that has a ``write()`` method as described above. With this extended >>>
————————————
Done。