zoukankan      html  css  js  c++  java
  • 习题 2:注解和#号


     程序里的注释是很重要的。它们可以用自然语言告诉你某段代码的功能是什么。想要临时移除一段代码时,你还可以用注释的方式临时禁用这段代码。这个习题就是学会如何在 Python 中使用注释。


     ex2.py

    # A comment, this is so you can read your program later.
    # Anything after the # is ignored by python.
    # 一个注释,这是为了让你以后可以阅读你的程序。
    # 在#之后的任何内容都会被python忽略。
    
    print("I could have code like this.") # and the comment after is ignored
    print("我可以有这样的代码。") #之后的注释被忽略
    
    # You can also use a comment to "disable" or comment out code:
    # print("This won't run.")
    # 您还可以使用注释来“禁用”或注释代码:
    # print("这不会运行。")
    
    print("This will run.")
    print("这将运行。")

     应看到的结果

      

     巩固练习 

    1. 弄清楚 # 字符的作用,而且记住它的名字(英文名 octothorpe 、pound character 、hash 或者 mesh)。
    2. 打开 ex2.py 文件,从后往前逐行检查。从最后一行开始,倒着逐个单词检查回去。

     扩展(批量、多行注释)

    1. python中的 # 多行注释用鼠标选定代码后按快捷键ctrl+/
    2. 在python中多行注释还可以用三对单引号'''    '''包含的或者三对双引号"""    """包含的,例如:
  • 相关阅读:
    hdu--4336--概率dp
    hdu--3905--dp
    codeforces--279--
    hdu--5023--线段树
    正则表达式
    vim编辑器使用
    圆头像控件,自动监听点击跳转到Activity
    ImageView切换两种状态下的模式
    string字符串截取
    Class对象获取方法
  • 原文地址:https://www.cnblogs.com/llr211/p/11367917.html
Copyright © 2011-2022 走看看