1.变量介绍

变量来源于数学,是计算机语言中能储存计算结果或能表示值的抽象概念,变量可以通过变量名访问,在指令式语言中,变量通常是可变的。

其中Teacher是变量名,zhangzexiang是变量值;

这句话意思是,把变量值zhangzexiang储存在变量名Teacher中。

Teacher="zhangzexiang"

print (Teacher)

2.用变量进行计算

2.1 这个就是第1章 打印输出 第2节 引号规则里面说的给变量名赋值。

a=6

b=4

print(a+b)

2.2 我们也可以将a+b的计算结果用c来代表,最后直接打印输出c。

a=6

b=4

c=a+b

print(c)

2.3 不止是数字,字母也是可以进行变量名赋值的。

a="zhang"

b="zexiang"

print(a+b)

2.4 自增自减

a=7

a=a-1

print (a)

3.大量练习

cars=100 #汽车数量

space_in_a_car=4.0 #汽车空间

drivers=30 #司机数量

passengers=90 #拼车数量

cars_not_driven=cars-drivers #空车数量=汽车数量-司机数量

cars_driven=drivers #汽车驱动=司机数量

carpool_capacity=cars_driven*space_in_a_car #拼车能力=汽车驱动*汽车空间

average_passengers_per_car=passengers/cars_driven #平均每辆车的乘客=拼车数量/汽车驱动

print("There are",cars,"cars available.") #有100辆汽车可用。

print("There are only",drivers,"drivers available.")#目前只有30名司机。

print("There will be",cars_not_driven,"empty cars today.")#今天将有70辆空车。

print("We can transport",carpool_capacity,"people today.")#我们今天可以运送120.0人。

print("We have",passengers ,"to carpool today.")#今天我们有90个拼车。

print("We need to put about",average_passengers_per_car,"in each car")#我们需要在每辆车里装上3.0个座位

my_name='Zed A.Shaw'

my_age=35 # not a lie

my_height=74 # inches

my_weight=180 #Lbs

my_eyes="Blue"

my_teeth="White"

my_hair="Brown"

print("Let's talk about %s."%my_name)

print("He's %d inches tall."%my_height)

print("He's %d pounds heavy."%my_weight)

print("Actually that's not too heavy.")

print("He's got %s eyes and %s hair."%(my_eyes,my_hair))

print("His teeth are usually %s depending on the coffee."%my_teeth) # this line is tricky , try to get it exactly right

print("If I add %d,%d,%d I get %d."%(my_age,my_height,my_weight,my_age+my_height+my_weight))

'''

让我们来讨论一下Zed A.Shaw。

他的74英寸高。

他是180磅重。

实际上,这并不太重。

他有蓝色的眼睛和棕色的头发。

他的牙齿通常是白色的,这取决于咖啡。

如果加35,74,180得到289。

'''

x=("There are %d types of people."%10)

binary="binary"

do_not="don't"

y=("Those who know %s and those who %s."%(binary,do_not))

print(x)

print(y)

print("I said: %r." %x)

print("I also said:%s." %y)

hilarious=False #滑稽的

joke_evaluation=("Isn't that joke so funny?! %r ") #笑话评价

print(joke_evaluation%hilarious)

w=("This is the left side of")

e=(" a string with a right side.")

print(w+e)

'''

There are 10 types of people.

Those who know binary and those who don't.

I said: 'There are 10 types of people.'.

I also said:Those who know binary and those who don't..

Isn't that joke so funny?! False

This is the left side of a string with a right side.

有10种类型的人。

知道二进制的和不知道二进制的。

我说:“有10种类型的人。”

我也说过:那些知道二进制和不知道二进制的人。

这个笑话好笑吗?假

这是一个有右侧的弦的左边。

'''

print("Mary had a little lamb.")

print("Its fleece was white as %s." %'snow')

print("And everywhere that Mary went.")

print("."*10)# what'd that do?

end1="C"

end2="h"

end3="e"

end4="e"

end5="s"

end6="e"

end7="B"

end8="u"

end9="r"

end10="g"

end11="e"

end12="r"

# watch that comma at the end. try removing it to see what happens

print(end1+end2+end3+end4+end5+end6,end=" ")

print(end7+end8+end9+end10+end11+end12)

'''

Mary had a little lamb.

Its fleece was white as snow.

And everywhere that Mary went.

..........

Cheese Burger

玛丽有只小羊羔。

它的羊毛像雪一样白。

和玛丽去的地方。

..........

奶酪汉堡。

'''

formatter=("%r %r %r %r") #格式器

print (formatter %(1,2,3,4))

print(formatter%("one","two","three","four"))

print(formatter%(True,False,False,True))

print(formatter%(formatter,formatter,formatter,formatter))

print(formatter%("I had this thing.",

"That you could type up right.",

"But it did't sing.",

"So I said goodnight."))

'''

1 2 3 4

'one' 'two' 'three' 'four'

True False False True

'%r %r %r %r' '%r %r %r %r' '%r %r %r %r' '%r %r %r %r'

'I had this thing.' 'That you could type up right.' "But it did't sing." 'So I said goodnight.'

print字符打错了, 字符串换行的时候要加, 与""号。

'''

#Exercise

#Here's some new strange stuff,remember type it exactly.

days="Mon Tue Wed Thu Fri Sat Sun"

months="Jan\nFeb\nMar\nApr\nMay\nJun\njul\nAug"

print("Here are the days:",days)

print("Here are the months:",months)

print("""

There's something going on Here.

With the three double-quotes.

We'll be able to type as much as we like.

Even 4 lines if we want , or 5 , or 6.""")

'''

Here are the days: Mon Tue Wed Thu Fri Sat Sun

Here are the months:

Jan

Feb

Mar

Apr

May

Jun

jul

Aug

There's something going on Here.

With the three double-quotes.

We'll be able to type as much as we like.

Even 4 lines if we want , or 5 , or 6.

现在是这样的日子:Mon Tue Wed Thu Fri Sat Sun

这里是几月:

1月

2月

3月

4月

5月

6月

7月

8月

这里有一些东西。

三个双引号。

我们可以输入我们喜欢的东西。

即使是4行,也可以是5或6。

'''

# Exercise

tabby_cat="\tI'm tabbed in."

persian_cat="I'm split\non a line."

backslash_cat="I'm\\a\\cat."

fat_cat="""

I'll do a list:

\t*Cat food

\t*Flishies

\t*Catnip\n\t*Grass

"""

print(tabby_cat)

print(persian_cat)

print(backslash_cat)

print(fat_cat)

'''

I'm tabbed in.

I'm split

on a line.

I'm\a\cat.

I'll do a list:

*Cat food

*Flishies

*Catnip

*Grass

'''

python设置变量age和tall的值、编写一个_Python变量学习相关推荐

  1. JAVA 编写一个员工类,成员变量和成员方法自拟,编写一个测试类

    课后习题练习 3.4 编写程序实现以下功能: (1).员工类(Emploee):c=成员变量包含员工号和员工姓名,成员方法包含构造方法和输出方法(输出员工信息). (2). 部门主管类(Manager ...

  2. 【Python 3.7】喜欢的图书:编写一个名为 favorite_book() 的函数,其中包含一个名为 title 的形参。

    [Python 3.7]喜欢的图书:编写一个名为 favorite_book() 的函数,其中包含一个名为 title的形参.这个函数打印一条消息,如 One of my favorite books ...

  3. python变量值发生变化时输出语句_有一个字符串变量s = 'python program',语句print(s[1:5:2]) 的输出结果是:_学小易找答案...

    [判断题]print('936'.isdigit()) 的输出结果是 True [单选题]下面关于"义务论"伦理学和"后果论"伦理学的比较描述错误的一项是?() ...

  4. python猜数字游戏、在程序中预设一个_python 语法基础练习题

    python 语法基础练习题 1. 分别解释"=","==","+="的含义(口述) 2.两个变量值的关系?(口述) n1 = 123456 ...

  5. 编写一个c语言程序 求e的值,编写一个程序求e的值_相关文章专题_写写帮文库

    时间:2019-05-15 01:58:18 作者:admin 3.2 代数式的值 做课人 尹圣军 [教学目标] 知识与技能 能解释代数式值的实际意义,了解代数式值的概念. 过程与方法 经历观察.实验 ...

  6. Python番外篇:教你如何编写一个GIF录屏工具

    hello,大家好,我是wangzirui32,今天我们来学习如何编写一个GIF录屏工具,开始学习吧! 1. 项目准备 我们需要PIL库对屏幕进行截取,使用imageio对截取的图像进行拼接,合成为G ...

  7. python请输出如下图形的程序_编写一个python程序,输出如下图形效果。

    [简答题]2.变量与常量作业-.docx [简答题]8.类和对象作业-.docx [计算题]计算 [计算题]求极限 [简答题]使用FileReader对象把Java源文件显示在控制台窗口 [单选题]设 ...

  8. 生日快乐python编程代码_如何用C语言编写一个很炫的生日快乐的程序?

    我也是网上找的,把下面的话改一下差不多了 很多人说没法运行,我也不是专业的,但是这用codeblock c++是可以运行的,其他的我不知道 #include #include #include #de ...

  9. python定义变量参数_Python变量定义与使用

    前言 对于任何编程语言都存在对数据的处理,比如数字.字符串.字符等,我们可以直接使用数据,同时还可以将数据保存到变量中,方便以后使用.什么是变量?在任何语言里面都一样,可以把它看成是个小容器,专门用来 ...

最新文章

  1. tomcat架构分析(valve机制)【转】
  2. 借助混沌工程工具 ChaosBlade 构建高可用的分布式系统
  3. os_mbox.c(全)
  4. 对java注解的深入理解
  5. html frame跳转实例,HTML frame标签怎么用?frame标签的具体使用实例
  6. flask框架_Flask框架的入门:Hello world
  7. sh linux 一组命令,linux中的组命令和子shell
  8. mysql如何给text字段添加索引_MySQL 是如何利用索引的
  9. 发现新的预言梦种类:预言梦投射
  10. 【TensorFlow系列】【九】利用tf.py_func自定义算子
  11. VB装linux教程,RHEL6下VirtualBox安装Linux系统
  12. Dictionary 索引超出数组界限
  13. ocjp 考试题之六
  14. python中文版加密解密_python - 入门-对中英文加密解密
  15. 计算机知识培训内容,学电脑,培训哪些内容
  16. 笔记本电脑切换Fn功能键
  17. 解决vs code使用code runner无法输入数据问题
  18. oracle数据库处于recover,oracle数据库recover和restore的区别
  19. mac 下openOffice服务的安装
  20. 今日头条Go建千亿级微服务的实践

热门文章

  1. 京东数据化运营(二)- 转化率
  2. Python中next()函数、iter()以及next(iter())函数的用法详解
  3. 网易云信im 的聊天记录展示
  4. MFC的使用——在共享DLL中使用MFC、在静态库中使用MFC
  5. pagehelper circular references
  6. Store Forwarding
  7. 用深度学习构造聊天机器人简介
  8. css样式匹配苹果个型号手机
  9. 投资转型:实体店铺,投资经营复盘
  10. 『矩阵论笔记』详解最小二乘法(矩阵形式求导)+Python实战