Exercise 2 Comments and Pound Characters

Comments and Pound Characters

注释和英镑字符

Comments are very important in your programs. They are used to tell you what something does in English, and they are used to disable parts of your program if you need to remove them temporarily.
Here’s how you use comments in Python:

注释在编程中是非常重要的。他们是用英语来告诉其含义,他们也常常不是程序的一部分如果你需要临时的移动他们。
这里将告诉你怎样再python中使用注释:

ex2.py

1 # A comment, this is so you can read your program later.
2 # Anything after the # is ignored by python.
3
4 print("I could have code like this.") # and the comment after is ignored
5
6 # You can also use a comment to "disable" or comment out code:
7 # print("This won't run.")
8
9 print("This will run.")

From now on, I’m going to write code like this. It is important for you to understand that everything does not have to be literal. Your screen and program may visually look different, but what’s important is the text you type into the file you’re writing in your text editor. In fact, I could work with any text editor and the results would be the same.

从现在开始,我将写下这样的代码。注释对于你理解一切不是文字的。你的屏幕和程序上可能看到的不同,但是重要的就是你输入进去的这个文本也会写入你的编辑器中。事实上,我能够用任何的编辑器得到相同的结果。

What You Should See
你所看到的
$ python3.6 ex2.py
I could have code like this.
This will run.

Again, I’m not going to show you screenshots of all the Terminals possible. You should understand that the preceding is not a literal translation of what your output should look like visually, but the text between the first $ python3.6 … and last $ lines will be what you focus on.

这次,我向你没有展示终端可能的截图,你应该明白了程序不是一个文本翻译,你的输出应该是你现在所看到的,但是这些文本在第一个 $ python3.6 …
最后的 $ 将是你所关注的。

Study Drills
  1. Find out if you were right about what the # character does and make sure you know what it’s called (octothorpe or pound character).

看看你对 # 字符理解的是否正确,以确保你知道什么是注释符或者是英镑符。

  1. Take your ex2.py file and review each line going backward. Start at the last line, and check each word in reverse against what you should have typed.

提取您的 ex2.py 文件,并查看每行的后退内容。 从最后一行开始,然后反向检查每个单词是否与您输入的内容相对应。

  1. Did you find more mistakes? Fix them.

你找到错误了吗?修复它们

  1. Read what you typed above out loud, including saying each character by its name. Did you find more mistakes? Fix them.

大声读你输入的内容,包括每个字符以及名字。你找到更多的错误了吗?修复它。

Common Student Questions
类似的学生的问题

Are you sure # is called the pound character? I call it the octothorpe because that is the only name that no one country uses and that works in every country.

你确定 # 称为英镑符吗?我称它为 井号符因为这不是一个国家使用的唯一名称,在每个国家都通用。

Every country thinks its name for this one character is both the most important way to do it and the only way it’s done.

对于这个名字来说,每个国家认为它的名字既有最重要的,也是唯一的。

To me this is simply arrogance and, really, y’all should just chill out and focus on more important things like learning to code.

对我来说简直是自大,事实上,你都应该冷静下来并且并且集中于更重要的事情比如说学习编程。

Why does the # in print(“Hi # there.”) not get ignored? The # in that code is inside a string, so it will be put into the string until the ending " character is hit.

为什么这个 # 在 print(“Hi # there.”) 中没有忽略?这里的 # 被认为是在字符串中的一部分,因此它将作为一个字符串,直到最后的 " 将它隐匿。

Pound characters in strings are just considered characters, not comments.

英镑符在字符串中仅仅被认为是字符,而不是命令。

How do I comment out multiple lines? Put a # in front of each one.

我怎样注释多行?在每一行的前面键入 #

I can’t figure out how to type a # character on my country’s keyboard. How do I do that? Some countries use the ALT key and combinations of other keys to print characters foreign to their language. You’ll have to look online in a search engine to see how to type it.

在我的城市的键盘上,我不能解决如何打出 # 这个字符这个问题。我应该怎么做?有些国家使用的是 ALT 键盘并结合了他们自己国家的语言来输入字符。你将必须在网上的搜索引擎中找找如何打出 #

Why do I have to read code backward? It’s a trick to make your brain not attach meaning to each part of the code, and doing that makes you process each piece exactly. This is a handy error-checking technique.

为什么我必须读代码的后面?这是一个技巧能确保你的大脑对每个代码不上心,并且这样做能够确保你对每个代码的精确。这是一个很好的检查报错的方法。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值