码迷,mamicode.com
首页 >  
搜索关键字:def    ( 28626个结果
Groovy基础——MetaClass详解
一、拦截方法调用和参数获取 示例1: class MyClass{ ?def hello(){ ??‘invoked hello directly‘ ?} ?def invokeMethod(String name, Object args){ ??return "unknown method $name(${args.join(‘, ‘)})"...
分类:Web程序   时间:2015-02-28 13:13:05    阅读次数:177
Ruby七天入门(2 函数,数组和类)
DAY 2第二天学习继续,今天重点学习函数,数组和类等编程的基本要素。2.1 函数2.1.1 简单定义 def tell_me puts true end 定义一个简单的函数(无参无返回值)很简单,使用def end包裹函数体即可。 2.1.2 参数def tell_me(a) puts a end tell_me 1 1 => nil 使用参数和其他语言类似,加括号加变量名即可。 2.1.2....
分类:编程语言   时间:2015-02-28 10:18:49    阅读次数:231
Python 单例
1 class Singleton(object): 2 def __new__(cls, *args, **kwargs): 3 if '_inst' not in vars(cls): 4 cls._inst = super(Singleton,...
分类:编程语言   时间:2015-02-28 10:05:31    阅读次数:128
四分历python实现
根据一个新加坡人的c代码改写成python代码 1 ''' 四分历''' 2 3 # 4 zq = 0 5 month = 0 6 7 def main(): 8 global month 9 year = 1 10 rb_year = 0 11 ...
分类:编程语言   时间:2015-02-28 00:12:59    阅读次数:188
BZOJ 3892 [Usaco2014 Dec]Marathon 动态规划
题目大意:给定n个点,定义从一个点到另一个点的距离为曼哈顿距离,要求从点1依次走到点n,中途可以跳过k个点不走,求最小距离和 令f[i][j]表示从第一个点走到第i个点中途跳过j次的最小距离和 则有f[i][j]=min{f[i-k-1][j-k]+dis[i-k-1][i]} 时间复杂度O(n^3) #include #include #include #include #def...
分类:其他好文   时间:2015-02-27 21:37:46    阅读次数:233
Python学习之类
class Person:def __init__(self, name):self.name = namedef sayHi(self):print('Hello, my name is'+ self.name)p = Person('Swaroop')p.sayHi()
分类:编程语言   时间:2015-02-27 16:43:51    阅读次数:116
ruby block each
#!/usr/local/bin/ruby?-w # # # def?call_each ???animals?=?%w{ant?bee?cat?dog?elk} ???for?animal?in?animals ?????yield?animal ???end end call_each?{|animal_block|?puts?...
分类:其他好文   时间:2015-02-27 15:21:36    阅读次数:162
Python--动态类型
函数的参数传递,本质上传递的是引用。比如说:def f(x): x = 100 print xa = 1f(a)print a输出结果为:1001参数x是一个新的引用,指向a所指的对象。如果参数是不可变(immutable)的对象,a和x引用之间相互独立。对参数x的操作不会影响引用a。这...
分类:编程语言   时间:2015-02-26 18:18:19    阅读次数:156
python IsWindowEnabled遍历windows的所有窗口并输出窗口标题
这段代码可以让Python遍历当前Windows下所有运行程序的窗口,并获得运行窗口的标题输出#! /usr/bin/env python# -*- coding: utf-8 -*-from win32gui import *titles = set()def foo(hwnd,mouse): ....
分类:编程语言   时间:2015-02-26 18:18:09    阅读次数:469
Algorithm: quick sort implemented in python 算法导论 快速排序
1 import random 2 3 def partition(A, lo, hi): 4 pivot_index = random.randint(lo, hi) 5 pivot = A[pivot_index] 6 A[pivot_index], A[hi] = ...
分类:编程语言   时间:2015-02-26 14:51:41    阅读次数:183
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!