python04 变量和变量的命名
来源:互联网 发布:中国历年gdp数据图表 编辑:程序博客网 时间:2024/06/06 18:13
我的理解,变量和代数基本上是一个概念。
ex4.py
cars = 100space_in_a_car = 4.0drivers = 30passengers = 90cars_not_driven = cars - driverscars_driven = driverscarpool_capacity = cars_driven * space_in_a_caraverage_passengers_per_car = passengers / cars_drivenprint "There are", cars, "cars available."print "There are only", drivers, "drivers available."print "There will be", cars_not_driven, "empty cars today."print "We can transport", carpool_capacity, "people today."print "We have", passengers, "to carpool today."print "We need to put about", average_passengers_per_car, "in each car."
1-8行中的那些单词就是变量,同时可以看到,用=号来给变量赋值
稍微改下代码
space_in_a_car = 4drivers = 30passengers = 90cars_not_driven = cars - driverscars = 100cars_driven = driverscarpool_capacity = cars_driven * space_in_a_caraverage_passengers_per_car = passengers / cars_drivenprint "There are", cars, "cars available."print "There are only", drivers, "drivers available."print "There will be", cars_not_driven, "empty cars today."print "We can transport", carpool_capacity, "people today."print "We have", passengers, "to carpool today."print "We need to put about", average_passengers_per_car, "in each car."
然后运行一下:
从而猜测,变量如果未赋值是不能使用的
再改下代码
cars space_in_a_car = 4drivers = 30passengers = 90cars_not_driven = cars - driverscars_driven = driverscarpool_capacity = cars_driven * space_in_a_caraverage_passengers_per_car = passengers / cars_drivenprint "There are", cars, "cars available."print "There are only", drivers, "drivers available."print "There will be", cars_not_driven, "empty cars today."print "We can transport", carpool_capacity, "people today."print "We have", passengers, "to carpool today."print "We need to put about", average_passengers_per_car, "in each car."
果然。
至于NameError前的的单词 cars为什么会显示"锘缟ars",我也没弄明白,有知道的可以告诉我。
- python04 变量和变量的命名
- js中变量的声明和变量的命名规范
- 变量名和常数的命名方式
- 程序函数和变量的命名
- 变量的命名和使用技巧
- C#变量的概念和命名规范
- 变量名和常数的命名方式
- 变量和方法命名的最佳实践
- xml的变量命名和布局
- 变量和方法命名的最佳实践
- swift常量和变量的命名规则
- 变量的命名和使用规则
- ios变量的命名规则和规范
- 方法和变量命名的最佳实践
- 变量的命名、定义和初始化
- 变量和类的命名规则
- Python中变量的命名和使用
- Java变量的命名、定义和初始化
- Hadoop之hive学习
- Windows8和CentOS6.4(64)双系统硬盘安装
- 我要积分
- 使用VC时一些容易犯的错误
- java中Calendar日期对象的一些简单应用
- python04 变量和变量的命名
- Definition of 'Strip'
- 关于com接口调用的反汇编
- 前端性能优化:使用Array.prototype.join代替字符串连接
- 在gnome3 修改eclipse 标签页高度过高的问题
- Magento组合查询语句的Complex_filter和Filter
- 双系统删除Linux引导(MbrFix.exe)
- Xp无法加载用户配置文件
- 英语