zoukankan      html  css  js  c++  java
  • Head First Python 读书笔记

      记录一下这段时间看《Head First Python》记录的一些小知识,只是记了很少一部分,有需要的话以后再添加吧。


    for循环的使用:

      for 目标标识符 in 列表:
        处理代码

    if语句的使用:

      if 满足某个条件:
        true组
      else:
        false组
    • len() BIF会提供某个数据对象的长度,或集合的项数。

    • isinstance() BIF会检查一个标识符是否为某个指定类型。

    • 使用可选参数:  def print_lol(the_list , level = 0)

    下面附一些代码:

    #code of open file
    def get_coach_data(filename):
        try:
            with open(filename) as f:
                data = f.readline()
            temp = data.strip().split(',')
            return (AthleteList(temp.pop(0) , temp.pop(0) , temp)
        except IOError as e:
            print('File Error:' + str(e))
            return (None)
    #code with great style
    def top3(self):
        return (sorted(set([sanitize(i) for i in self]))[0:3])
    #demo of pickle
    import pickle
    try:
        with open ("data.pickle" , 'wb') as mysavedata:
            pickle.dump([1 , 2 , 'three'] , mysavedata)
    except pickle.PickleError as e:
        print('File Error:' + str(e))
    #demo of class
    class AthleteList(list):
        det __init__(self , a_name , a_dob = None , a_times = []):
            self.name = a_name
            self.dob = a_dob
            self.extend(a_times)
        def top3(self):
            return (sorted(set([sanitize(i) for i in self]))[0:3])
  • 相关阅读:
    Eclipse在线安装主题(color theme)以及安装color theme第三方主题(图文)
    eclipse快速打开文件目录
    获取项目路径
    阿里巴巴Druid数据源及使用
    project_online
    色区-论坛
    mysql密码
    jre变更目录或修改文件名后报错解决
    9个基于Java的搜索引擎框架
    面试参考
  • 原文地址:https://www.cnblogs.com/H-Vking/p/5572358.html
Copyright © 2011-2022 走看看