【Python 3.6.1】hello world!
开发中第一个小程序,hello world!
1 2 3 4 5 6 7 |
[root@dt ~]# python Python 3.6.1 (default, Jul 2 2017, 16:09:42) [GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> print ("hello world!") hello world! >>> |
python2和3是有区别的,python3需要括号,如果直接 print “hello world”,那么会出现如下错误:
1 2 3 4 5 6 |
>>> print "hello world" File "<stdin>", line 1 print "hello world" ^ SyntaxError: Missing parentheses in call to 'print' >>> |
python的语法相对较宽松,比如在print时,字符串用双引号或单引号都是支持的,但是字符串不加引号是不允许的。建议使用双引号,避免由于字符串中包含单引号导致的错误。