Published 7月 24, 2018 by with 0 comment

習題2 - 注釋與#號




用Notepad++打下列的程式碼,
另存為ex2.py.
# A commect, this is so you can read your program later.
# Anything after the # is ignored by python.

print ("I could code like this.") # and the comment after is ignored.

# You can also use a comment to "disable" or comment out code:
# print ("This won't run.")

print ("This will run.")

然後用Windows的cmd, 執行python打開它
C:\Windows\System32>cd C:\Users\Peter\Desktop\Python\LP3THW

C:\Users\Peter\Desktop\Python\LP3THW>python .\ex2.py
I could code like this.
This will run.

C:\Users\Peter\Desktop\Python\LP3THW>

完成.

接下來修改程式, 觀察有啥不同.
比如, line 1 多加個#號.
## A commect, this is so you can read your program later.
# Anything after the # is ignored by python.

print ("I could code like this.") # and the comment after is ignored.

# You can also use a comment to "disable" or comment out code:
# print ("This won't run.")

print ("This will run.")

Line 1多加個#號, 沒影響.
C:\Users\Peter\Desktop\Python\LP3THW>python .\ex2.py
I could code like this.
This will run.

C:\Users\Peter\Desktop\Python\LP3THW>


比如, line 4 print ("#I could  code like this.") 多加個#號.
# A commect, this is so you can read your program later.
# Anything after the # is ignored by python.

print ("#I could code like this.") # and the comment after is ignored.

# You can also use a comment to "disable" or comment out code:
# print ("This won't run.")

print ("This will run.")

Line 4 的#號沒有被忽略掉.
C:\Users\Peter\Desktop\Python\LP3THW>python .\ex2.py
#I could code like this.
This will run.

C:\Users\Peter\Desktop\Python\LP3THW>



最初發表 / 最後更新: 2018.07.24 / 2018.07.24

0 comments:

張貼留言