Python 基础 print打印&input输入值,Python变量,Python常量


print("python hello world") #打印一行内容 "python hello world"

input("请输入内容") #接收输入内容

什么是变量
#变量即变化的量,核心是“变”与“量”二字,变即变化,量即衡量状态。


Python 变量
数值变量
字符串变量
布尔值变量

为什么要有变量



变量的定义规范
#1. 变量名只能是 字母、数字或下划线的任意组合
#2. 变量名的第一个字符不能是数字
#3. 关键字不能声明为变量名['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']
 
   定义方式:
#驼峰体
AgeOfOldboy = 56 
NumberOfStudents = 80
#下划线(推荐使用)
age_of_oldboy = 56 
number_of_students = 80

定义变量名不好的方式
#1. 变量名为中文、拼音
#2. 变量名过长
#3. 变量名词不达意
定义变量会有:id,type,value
#1 等号比较的是value,
#2 is比较的是id

#强调:
#1. id相同,意味着type和value必定相同
#2. value相同type肯定相同,但id可能不同,如下
>>> x='Info Egon:18'
>>> y='Info Egon:18'
>>> id(x)
4376607152
>>> id(y)
4376607408
>>> 
>>> x == y
True
>>> x is y
False
View Code

 

 

 




posted @ 2022-05-05 14:24  谢端阳  阅读(175)  评论(0)    收藏  举报