在mac环境下记录Python的学习笔记之基本介绍

作者: admin 分类: Python 发布时间: 2019-03-28 22:22  阅读: 604 views

Python 是一种解释性、面向对象、动态数据类型的高级程序设计语言。
Python 有Guido van Rossum于1989年底发明,第一个公开发行版发行与1991年。
python 遵循GPL(GNU General Public License)协议

Python 特点如下
1.Python有相对较少的关键字,结构简单,和明确定义的语法,学习比较简单。
2.Python代码定义的更清晰。源码更易维护。代码可读性高。
3.Python具有一个丰富的库,跨平台,在Unix、windows、Mac兼容性好
4.开放性、可移植、可扩展,即时调试。
5.Python支持主要的商业数据库连接。
6.可嵌入到c/c++程序。

'''
设置python的安装路径,防止执行时,找不到解释器.
上面这种是写死了路径,
推荐下面这种
#!/usr/bin/env python 
第二种会去环境设置中查找
'''

#!/usr/bin/python 
# -*- coding: UTF-8 -*-

'''
如有中文字符,需要加这句话,必须加在前面,Python2.x是ASCII编码格式 
Python3.x默认为utf-8编码,可以不用设置
'''

Python的几个重要环境变量

PYTHONPATH        PYTHONPATH是Python搜索路径,默认我们import的模块都会从PYTHONPATH里面寻找。
PYTHONSTARTUP     Python启动后,先寻找PYTHONSTARTUP环境变量,然后执行此变量指定的文件中的代码。
PYTHONCASEOK      加入PYTHONCASEOK的环境变量, 就会使python导入模块的时候不区分大小写.
PYTHONHOME        另一种模块搜索路径。它通常内嵌于的PYTHONSTARTUP或PYTHONPATH目录中,使得两个模块库更容易切换。

 

Python的命令行参数

python -d 在解析时显示调试信息
python -O 生成优化代码
python -S 启动时不引入查找Python路径的位置
python -V 显示Python的版本号
python -c cmd 执行Python脚本,并将结果作为cmd字符串
python xxx.py 执行指定脚本

可以使用 python -h 来 查看各参数的帮助信息
deathearth:~ chenhailong$ python -h
usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ...
Options and arguments (and corresponding environment variables):
-B     : don't write .py[co] files on import; also PYTHONDONTWRITEBYTECODE=x
-c cmd : program passed in as string (terminates option list)
-d     : debug output from parser; also PYTHONDEBUG=x
-E     : ignore PYTHON* environment variables (such as PYTHONPATH)
-h     : print this help message and exit (also --help)
-i     : inspect interactively after running script; forces a prompt even
         if stdin does not appear to be a terminal; also PYTHONINSPECT=x
-m mod : run library module as a script (terminates option list)
-O     : optimize generated bytecode slightly; also PYTHONOPTIMIZE=x
-OO    : remove doc-strings in addition to the -O optimizations
-R     : use a pseudo-random salt to make hash() values of various types be
         unpredictable between separate invocations of the interpreter, as
         a defense against denial-of-service attacks
-Q arg : division options: -Qold (default), -Qwarn, -Qwarnall, -Qnew
-s     : don't add user site directory to sys.path; also PYTHONNOUSERSITE
-S     : don't imply 'import site' on initialization
-t     : issue warnings about inconsistent tab usage (-tt: issue errors)
-u     : unbuffered binary stdout and stderr; also PYTHONUNBUFFERED=x
         see man page for details on internal buffering relating to '-u'
-v     : verbose (trace import statements); also PYTHONVERBOSE=x
         can be supplied multiple times to increase verbosity
-V     : print the Python version number and exit (also --version)
-W arg : warning control; arg is action:message:category:module:lineno
         also PYTHONWARNINGS=arg
-x     : skip first line of source, allowing use of non-Unix forms of #!cmd
-3     : warn about Python 3.x incompatibilities that 2to3 cannot trivially fix
file   : program read from script file
-      : program read from stdin (default; interactive mode if a tty)
arg ...: arguments passed to program in sys.argv[1:]

Other environment variables:
PYTHONSTARTUP: file executed on interactive startup (no default)
PYTHONPATH   : ':'-separated list of directories prefixed to the
               default module search path.  The result is sys.path.
PYTHONHOME   : alternate <prefix> directory (or <prefix>:<exec_prefix>).
               The default module search path uses <prefix>/pythonX.X.
PYTHONCASEOK : ignore case in 'import' statements (Windows).
PYTHONIOENCODING: Encoding[:errors] used for stdin/stdout/stderr.
PYTHONHASHSEED: if this variable is set to 'random', the effect is the same
   as specifying the -R option: a random value is used to seed the hashes of
   str, bytes and datetime objects.  It can also be set to an integer
   in the range [0,4294967295] to get hash values with a predictable seed.

python的hello,world输出

#!/usr/bin/python 
# -*- coding: UTF-8 -*-

print "hello world!"
print ("hello,world!")
print "你好,世界!"

'''输出结果如下
hello world!
hello,world!
'''

Python的开发工具

eclipse   -PyDev(可在 Eclipse marketplace中查找并自行安装)


   原创文章,转载请标明本文链接: 在mac环境下记录Python的学习笔记之基本介绍

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!

发表评论

电子邮件地址不会被公开。 必填项已用*标注

更多阅读