zoukankan      html  css  js  c++  java
  • python学习基础之变量

    • 变量名只能包含字母、数字和下划线。变量名可以字母或下划线打头,但不能以数字打 头,例如,可将变量命名为message_1,但不能将其命名为1_message。
    • 变量名不能包含空格,但可使用下划线来分隔其中的单词。例如,变量名greeting_message 可行,但变量名greeting message会引发错误。
    • 不要将Python关键字和函数名用作变量名,即不要使用Python保留用于特殊用途的单词

    Python中关键字

    关键字都有特殊含义,如果用作变量名,将引发错误:

      Flase  class  finally  is  return  None  continue  for  lambda  try  True  

      def     from  nonlical  while  and  del  global  not  with  as  elif  if  or 

      yield   assert  else  import  pass  break  except  in  raise

    Python内置函数

    使用函数名作为变量,虽然不会导致错误,但是会覆盖这些函数的行为:

       abs()      divmod()      input()      open()      staticmethod()    

       all()        enumerate()     int()          ord()        str()

       any()      eval()         isinstance()     pow()       sum()

       basestring()   execfile()        issubclass()     print()      super()

       bin()       file()          iter()        property()    tuple()

       bool()       filter()        len()        range()       type()

       bytearray()   float()        list()        raw_input()     unichr()

       callable()     format()      locals()       reduce()      unicode()

       chr()       frozenset()      long()        reload()       vard() 

       classmethod()   getattr()      map()        repr()        xrange()

       cmp()      globals()      max()        reversed()     zip()  

       compile()     hasattr()       memoryview()     round()       _import_()

       complex()    hash()         min()        set()       apply()  

       delattr()      help()         next()        setattr()       buffer()

       dict()       hex()         object()      slice()       coerce()

       dir()         id()          oct()        sorted()      intern()

    在2.7中print不是函数是关键字,python3中没有内置函数Unicode。

    变量命名:

    1.变量名应既简单又具有描述性。如:name比n好;

    2.慎用小写字母l和大写字母O,容易看成数字的1和0。

      

  • 相关阅读:
    Ngui使用随心记
    Ngui分辨率适配
    最大堆(优先队列)
    循环队列 & 栈的共用空间
    C#顺序表 & 单向链表(无头)
    IntelliJ Idea 常用快捷键列表
    写增删改查遇到的小问题总结
    用JS解决html页面间获取context-path问题
    html 页面如何获得url中的参数
    @RequestBody和@RequestParam区别
  • 原文地址:https://www.cnblogs.com/yuruhao/p/6431994.html
Copyright © 2011-2022 走看看