ubuntu下进行python操作,更易于开发,安装python及其外部结构包比较简单,可适合开发,提示效率。
ubuntu系统中自带有python2。
在ubuntu下安装python3的方法比较简单,在网络畅通的状态下,键入命令:
sudo apt-get install python3
查看python的版本或者是进去python的交互界面,可以直接输入python或者python3(打开ubuntu中Terminal快捷键的方式为->(ctrl+alt+t))
hsz@ubuntu:~$ python
Python 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
hsz@ubuntu:~$ python3
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
第一个python程序,打印出来hello world
方式一:
打开terminal,进入python的交互模式,输入print(“hello world”)
>>> print("hello world")
hello world
>>>
方式二:
建立.py文件
打开Terminal,使用cd命令切换到.py的目录下
运行.py文件,输入python3 helloWorld.py
使用python2的时候可能不兼容代码中含有中文,需要在py文件首行添加一句代码:
#-*- coding=utf-8-*- 或者 #coding=utf-8
在python中添加注释可以通过使用#(使用井号), 或者’’’ ’’’(三个单引号或者三个双引号,成对出现)
欢迎大家关注我的个人公众号,同样的也是和该博客账号一样,专注分析技术问题,我们一起学习进步