zoukankan      html  css  js  c++  java
  • Python Special Syntax 3:删除对象和dir函数

    一个Python文件(py后缀,假设是test.py)就是一个module,可以import  test; 也可以 from test import method1(), field1这样子用

    f=98
    print(f)
    del  f
    print(f)  #这行会报错:NameError: name 'f' is not defined

    内建的dir函数来列出模块定义的标识符。标识符有函数、类和变量。

    shoplist=['apple','banana','orange']
    shoplist.append('pear')
    print(shoplist)
    shoplist.remove('banana')
    print(shoplist)
    shoplist.__delitem__(0)
    print(shoplist)

    Output:

    ['apple', 'banana', 'orange', 'pear']
    ['apple', 'orange', 'pear']
    ['orange', 'pear']

     在print语句的结尾使用了一个 逗号 来消除每个print语句自动打印的换行符。这样做有点难看,不过确实简单有效。 

    列表的sort方法来对列表排序。需要理解的是,这个方法影响列表本身,而不是返回一个修改后的列表

  • 相关阅读:
    Munge
    file upload custom form
    随笔摘要
    生成css 和 清缓存
    drupal commit 原则
    Git reset --hard
    www-data
    301/302的区别
    什么是request_uri
    in_array foreach array_search的性能比较
  • 原文地址:https://www.cnblogs.com/yanyuge/p/3822108.html
Copyright © 2011-2022 走看看