Python 0基础:2.1变量的定义

110 阅读1分钟

在不使用变量的情况下:

print('今天的天气很好,晴天了')  
print('今天的天气很好,晴天了')  
print('今天的天气很好,晴天了')  
print('今天的天气很好,晴天了')

重复的值 书写/修改起来都很麻烦

在使用变量的情况下:

# 变量的格式 : 变量的名字 = 变量的值
weather = '今天的天气很好,晴天了!!!!'    
print(weather)  
print(weather)  # 注意:变量名不需要使用引号包裹
print(weather)  
print(weather)

定义变量后可以使用变量名来访问变量值

应用场景

img='https://img13.360buyimg.com/babel/s580x740_jfs/t1/92557/10/15252/173783/60a60c58Eaec1cb70/466903cb1e5a5d82.jpg!cc_290x370.webp'  
print(img)

可直接访问图片


说明:

  • 变量即是可以变化的值,可以随时进行修改。
  • 程序就是用来处理数据的,而变量就是用来存储数据的。