zoukankan      html  css  js  c++  java
  • 变量与常量

    变量的作用

      昵称,代指内存里某个地址中保存的内容存储程序的中间结果,方便后面的程序调用

      官方介绍 :Variables are used to store information to be referenced and manipulated in a computer program. They also provide a way of labeling data with a descriptive name, so our programs can be understood more clearly by the reader and ourselves. It is helpful to think of variables as containers that hold information. Their sole purpose is to label and store data in memory. This data can then be used throughout your program.

    声明 变量

      变量名 + 赋值符号 + 变量的值

      eg : name = alex

    变量定义的规则

    1. 变量名只能是 字母、数字或下划线的任意组合
    2. 变量名的第一个字符不能是数字
    3. 以下关键字不能声明为变量名
    4. ['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']
    5. 官方推荐用下话线的方式来命名如:age_of_you = 23

    变量的赋值
      name1 = "anna"  name2 = "wuan"
      变量name1,变量name2分别指向一块内存地址
      name1 = anna
      name2 = name1
      变量name1,name2指向同一内存地址,修改name1的值,那么的内容不变

    不使用中间变量交换两个变量的值:
    b, a = a, b
    常量

      常量即指不变的量,如pai 3.141592653..., 或在程序运行过程中不会改变的量

      在Python中没有一个专门的语法代表常量,程序员约定俗成用变量名全部大写代表常量

  • 相关阅读:
    PHP如何采集网站数据
    十一. Go并发编程singleflight
    2. Go中defer使用注意事项
    九. Go并发编程context.Context
    3. Go中panic与recover注意事项
    Go 性能提升tips边界检查
    十.Go并发编程channel使用
    八. Go并发编程errGroup
    十二. Go并发编程sync/errGroup
    Go知识盲区闭包
  • 原文地址:https://www.cnblogs.com/leiyiming/p/12880239.html
Copyright © 2011-2022 走看看