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中没有一个专门的语法代表常量,程序员约定俗成用变量名全部大写代表常量

  • 相关阅读:
    美国首位女计算机博士荣获今年图灵奖
    此人需要关注一下
    Microsoft的壮大与IBM对Sun的收购
    文章介绍:Sexy Lexing with Python
    程序员的门道
    闲谈:敏捷与否的区分方法、对组织内部人员的现实作用与长远利益
    聊聊最俗的工厂相关话题
    人之患在好为人师
    TIOBE的头头儿和“反Java”的教授
    敏捷的核心究竟是什么
  • 原文地址:https://www.cnblogs.com/leiyiming/p/12880239.html
Copyright © 2011-2022 走看看