【python】基础-变量和运算符

  1. python中的变量
    每个变量使用前需赋值,赋值后才能创建
    等号赋值=
  • 等号左边变量名(见名知义)
  • 等号右边为变量指向的value
    变量名以字母 下划线 数字组成,不能以数字开头,区分大小写
  1. 大驼峰命名在python中通常用来定义类名
  2. python中常见的数据类型
    • int
    • str
    • bool
    • float
var = 'test'
var2 = 123
print(var,var2)

输出:test 123
python内置的关键字不可作为变量名

>>> print(keyword.kwlist)
['False', 'None', 'True', '__peg_parser__', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
  1. 运算符
    • 比较运算符
      <> ==
    • 逻辑运算符
      not and or
    • 赋值运算符

posted @ 2022-02-21 22:40  路途颇远虽迟但到  阅读(6)  评论(0)    收藏  举报