继续修行Python基础总结(注释|变量)

开始正式进入Python的学习

一、映入眼帘的注释语句:

首先来了解Python的环境变量注释语句:

#!/usr/bin/env python

  别的就不提及了只是说说这个/usr/bin/env这个有点厉害这个是你系统默认的python的环境变量。我们知道我们可以在系统中安装各种python。但是python的很多版本对于系统来说系统环境变量读到python的程序,如我们执行$ python aa.py 这种语句的时候,我们能够看到的显示结果是用什么版本的python解释的,并不是说越高越好,不是说你装了python3和python2.6然后就一定要用高版本的解释器来执行,而是就看这个路径这个路径描述的python环境就是系统环境。这样写的好处就是如果以后赋予文件执行权限后这个文件是可以自执行的。如$ ./aa.pyc 用这种自动执行的方式来让系统语言自动执行python。

其次就是第二条注释语言UTF8的编码:

# -*- coding:utf-8 -*-

这个只是在Python的版本2中使用,在python3中自动继承万国码。其实还有些比较复杂的东西,但是这个阶段就先理解到这里。

 二、Python中的变量

定义:

  变量就是代指一个变化的值;变量的格式,是由字母或下划线开头的,且仅包含数字、字母、下划线组成的字符串。而且系统中预留了很多的字符串是不能作为变量使用的,虽然依然可以给这些预留的变量赋值,但赋值的结果可能会导致各种不可预知的问题。已知的系统预留关键字如下:"and","as",assert","break","class","continue","def","del","elif","else","except","exec","finally","for","from","global","if","import","in","is","lambda","not","or","pass","print","raise","return","try","while","with","yield"

  查看内置函数的方法:

>>> dir(__builtins__)
['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BufferError', 'BytesWarning', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False', 'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 'ImportWarning', 'IndentationError', 'IndexError', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'NameError', 'None', 'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 'PendingDeprecationWarning', 'ReferenceError', 'RuntimeError', 'RuntimeWarning', 'StandardError', 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'True', 'TypeError', 'UnboundLocalError', 'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', 'ValueError', 'Warning', 'ZeroDivisionError', '__debug__', '__doc__', '__import__', '__name__', '__package__', 'abs', 'all', 'any', 'apply', 'basestring', 'bin', 'bool', 'buffer', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'cmp', 'coerce', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'execfile', 'exit', 'file', 'filter', 'float', 'format', 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'intern', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'long', 'map', 'max', 'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property', 'quit', 'range', 'raw_input', 'reduce', 'reload', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'unichr', 'unicode', 'vars', 'xrange', 'zip']
>>>  

  

  这里有老男孩一位资深老师的详细讲解

   

 
原文地址:https://www.cnblogs.com/MuHaiCheng/p/6917757.html