ITPub博客

首页 > 应用开发 > Python > python_基础_变量

python_基础_变量

原创 Python 作者:20170405 时间:2020-08-10 11:06:52 0 删除 编辑

  一、变量

  1.1

  变量的命名规范

  只能使用数字字母下划线,但是不能以数字开头,不能使用关键字。

  1.2

  小驼峰命名法

  除第一个单词之外,其他单词首字母大写。

  helloWorldMy = 1

  1.3

  大驼峰命名法

  大驼峰法把第一个单词是大写,后面的单词首字母也大写。

  HelloWorldMy = 1

  1.4

  下换线命名法

  my_functions = function

  1.4

  查看python所有关键字

  import keyword

  l = keyword.kwlist

  print(l)

  #['False', 'None', 'True', '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.5

  变量的定义

  name = 'perhaps'

  print(name)

  #perhaps

  1.6

  其他方式

  x = y =z = 1

  print(x,y,z)

  x,y,z = 1,2,3

  print(x,y,z)

  a,b,c = (1,2,3)

  print( a)   郑州性病医院 http://www.120zhongyuanyy.com/

  print(b)

  print(c)

  a,b,c = [1, 2, [1, 2, 3]]

  print(a)

  print(b)

  print(c)

  '''

  1 1 1

  1 2 3

  [1, 2, 3]

  Process finished with exit code 0


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69979119/viewspace-2710409/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: Python基础
请登录后发表评论 登录
全部评论

注册时间:2020-07-14

  • 博文量
    63
  • 访问量
    39790