Write a definition for a class named Kangaroo with the following methods:

  • An __init__ method that initializes an attribute named pouch_contents to an empty list
  • A method named put_in_pouch that takes an object of any type and adds it to pouch_contents.
class Kangaroo:
""" attributes: pouch_contents""" def __init__(self):
self.pouch_contents = list() def __str__(self):
temp = ''
for s in self.pouch_contents:
temp+=str(s)+ '\n'
return temp def put_in_pouch(self,obj):
self.pouch_contents.append(obj) k = Kangaroo()
k.put_in_pouch(1)
k.put_in_pouch(1.0)
k.put_in_pouch('hello sun')
k.put_in_pouch((1,2,3)) k1 = Kangaroo()
k1.put_in_pouch([1,2,3])
k1.put_in_pouch({'':'sun','':'yu'})
k1.put_in_pouch('this is k1')

from Thinking in Python

Exercises - Kangaroo的更多相关文章

  1. [Bhatia.Matrix Analysis.Solutions to Exercises and Problems]Contents

    I find it may cost me so much time in doing such solutions to exercises and problems....I am sorry t ...

  2. 6656 Watching the Kangaroo

    6656 Watching the KangarooDay by day number of Kangaroos is decreasing just liketiger, whale or lion ...

  3. 46 Simple Python Exercises (前20道题)

    46 Simple Python Exercises This is version 0.45 of a collection of simple Python exercises construct ...

  4. Gym 101981K - Kangaroo Puzzle - [玄学][2018-2019 ACM-ICPC Asia Nanjing Regional Contest Problem K]

    题目链接:http://codeforces.com/gym/101981/problem/K Your friend has made a computer video game called “K ...

  5. State Estimation for Robotics (Tim Barfoot) exercises Answers

    Here are some exercises answers for State Estimation for Robotics, which I did in June, 2017. The bo ...

  6. Linux command line exercises for NGS data processing

    by Umer Zeeshan Ijaz The purpose of this tutorial is to introduce students to the frequently used to ...

  7. 100 numpy exercises

    100 numpy exercises A joint effort of the numpy community The goal is both to offer a quick referenc ...

  8. 46 Simple Python Exercises-Very simple exercises

    46 Simple Python Exercises-Very simple exercises 4.Write a function that takes a character (i.e. a s ...

  9. E - Cheap Kangaroo(求多个数的最大公约数)

    Description There are N kangaroos going out to eat at an Indian restaurant. The ith kangaroo wants t ...

随机推荐

  1. [linux basic 基础]----同步信号量

    直接使用一个共享变量,来是两个线程之间进行切换是非常笨拙而且没有效率的:信号量--互斥量--这两者是相互通过对方来实现的:比如,如果想控制某一时刻只有一个线程可以访问一些共享内存,使用互斥量要自然一些 ...

  2. PUA

    约会技巧 kino技巧 被拒绝的应对方法 (1)一般约会7个小时后,就能带女生回家 (2)点菜时多点一点,以回家放菜为名 (3)理由要文雅 (4)开酒店的理由 第一时间触碰测试 (1)第一次约会要第一 ...

  3. silverlight 报 System.NullReferenceException 未将对象引用设置到对象的实例。

    在 Microsoft.Windows.Design.Platform.SilverlightMetadataContext.SilverlightXamlExtensionImplementatio ...

  4. 更改EGit的user settings中默认的location

    在系统的环境变量中添加变量HOME,值为C:\Users\Kane.Sun\ 记得要讲users改为首字母大写,不然可能会有问题.

  5. vs2015-Azure Mobile Service

    /App_Data /App_Start/ WebApiConfig.cs using System; using System.Collections.Generic; using System.C ...

  6. JAVA 流式布局管理器

    //流式布局管理器 import java.awt.*; import javax.swing.*; public class Jiemian2 extends JFrame{ //定义组件 JBut ...

  7. laravel下使用阿里云oss上传图片

    对小公司而言,使用阿里云oss比直接买硬盘要划算的多,不管从存储性价比上还是从网速负载上.最近因为公司的项目有比较大的图片存储访问需求,所以决定使用阿里云的oss. 在研究了一下以后,摆着不自己造轮子 ...

  8. Eclipse UML插件Green UML、AmaterasUML

    一.Green UML插件 1.查看Eclipse版本 查看当前电脑上安装的Eclipse版本(Help-About Eclipse Platform),是3.3.2版本的. 2.查看相应插件版本 然 ...

  9. android之Widget01

    ExampleAppWidgetProvider.java package com.example.mars_2600_widget01; import android.appwidget.AppWi ...

  10. python输出重定向

    0表示标准输入1表示标准输出2表示标准错误输出> 默认为标准输出重定向,与 1> 相同2>&1 意思是把 标准错误输出 重定向到 标准输出.&>file 意思是 ...