码迷,mamicode.com
首页 >  
搜索关键字:def    ( 28626个结果
python 装饰器
最近在学习廖雪峰的python教程,在装饰器的一章中有个思考题: 请编写一个decorator,能在函数调用的前后打印出‘begin call‘和‘end call‘的日志 import functools def log(params): def decorator(): @functools....
分类:编程语言   时间:2014-11-14 00:25:17    阅读次数:250
Python学习笔记(五)多进程实现并发服务器
每创建一个TCP连接,就创建一个进程。 代码如下: # coding: utf-8 import socket import os import sys import signal import errno from time import ctime def hanlde_sigchld(a, b...
分类:编程语言   时间:2014-11-14 00:13:05    阅读次数:294
孪生素数问题
描述写一个程序,找出给出素数范围内的所有孪生素数的组数。一般来说,孪生素数就是指两个素数距离为2,近的不能再近的相邻素数。有些童鞋一看到题就开始写程序,不仔细看题,咱们为了遏制一下读题不认真仔细的童鞋,规定,两个素数相邻为1的也成为孪生素数。输入第一行给出N(0 2 #include 3 #def....
分类:其他好文   时间:2014-11-14 00:08:01    阅读次数:212
vs创建dll工程
1.创建工程--->Win32工程。 2.选择dll类型 3.添加代码 4.添加def定义文件 5.向def文件中添加代码 LIBRARY CnBlogsDll EXPORTS class1 class2 func1 func2 data1 data2 其中data1,data2,func1,func2,class1,class2等是需要导出的符...
分类:其他好文   时间:2014-11-13 20:49:10    阅读次数:216
Python interview - lambda
Python 中的lambda函数也叫匿名函数,即,没有具体的名称。lambda的主题是一个表达式,而不是一个代码块,仅仅能在lambda表达式中封装有限的逻辑。 我们拿正常的定义函数的方式来做比较: def f(x): return x**2 print f(4) # result 16 用lambda可以这样写: g = lambda x : x**2 print...
分类:编程语言   时间:2014-11-13 19:01:35    阅读次数:248
Beginning Python From Novice to Professional (7) - 类
类 创建简单类: #!/usr/bin/env python __metaclass__ = type class Person: def setName(self,name): self.name = name def getName(self): return self.name def greet(self): print "Hello,world! I'm %s."...
分类:编程语言   时间:2014-11-13 18:57:27    阅读次数:295
HDU 2138 How many prime numbers
就是找素数。很水的题。模糊搜索一道题搜到的。 但是却 TLE 2次。把所有的 long long 改成 int ,%lld 改成 %d 就神奇的过了。 简直不可思议。 #include #include #include #include #include #include #include #include #include #include #include #include #def...
分类:其他好文   时间:2014-11-13 18:55:12    阅读次数:176
Python学习笔记(四)多进程的使用
python中多进程与Linux 下的C基本相同。 fork的基本使用 先看最简单的例子: # coding: utf-8 import os def my_fork(): pid = os.fork() if pid == 0: print 'this is child, pid = %d, pa...
分类:编程语言   时间:2014-11-12 22:58:05    阅读次数:300
[leetcode] Min Stack @ Python
原题地址:https://oj.leetcode.com/problems/min-stack/解题思路:开辟两个栈,一个栈是普通的栈,一个栈用来维护最小值的队列。代码:class MinStack: # @param x, an integer def __init__(self): ...
分类:编程语言   时间:2014-11-12 13:44:19    阅读次数:213
python(2)
可变参数def enroll(name, gender, age=6, city='Beijing'): print 'name:', name print 'gender:', gender print 'age:', age print 'city:', city调用:e...
分类:编程语言   时间:2014-11-11 12:20:57    阅读次数:240
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!