上一页 1 ··· 10 11 12 13 14
摘要: #include "stdafx.h"#include ////函数重载//namespace operator_test{ // //先定义一个类 // class CObject { public: CObject(int a) : m_a(a) { } int Get() { return m_a; } int Add(CObject& obj2) { return (this->Get() + obj2.Get()); } int operator+(CObject& obj2) { return (this->Get() + obj2. 阅读全文
posted @ 2013-11-24 11:26 sysnap 阅读(165) 评论(0) 推荐(0)
摘要: def cacls(x, y): try: return x/y except ZeroDivisionError: print("y can not be zerp") except TypeError: print("TypeError")print( cacls(10, 2) )print( cacls(10, 0) )print( cacls(10, "hello") )#用一个块捕捉多个异常def cacls_2(x, y): try: return x/y except (ZeroDivision... 阅读全文
posted @ 2013-11-21 20:59 sysnap 阅读(201) 评论(0) 推荐(0)
摘要: class CPerson: name = "default" __name2 = "inaccessable name" #类作用域内的变量可以被所有实例访问 def setname(self, name): #第一个参数self,是对象本身的引用,它也是方法和函数的重要区别元素,如果方法里面没有引用任何东西,可以不用有这个参数 self.name = name def getname(self): return self.name def greeting(self): print("hello " + self.name)... 阅读全文
posted @ 2013-11-21 20:34 sysnap 阅读(167) 评论(0) 推荐(0)
摘要: #不定长参数,这里prams是一个元组集合def print_params(*prams): for e in prams: print(e) print(prams) #输出('xxx', (1, 2, 3), 'hello')print_params("xxx", (1,2,3), "hello")#关键字参数,使用参数名提供的参数,主要用于明确每个参数的作用,例如def hello_print(greeting = "hello", name = "world"): print 阅读全文
posted @ 2013-11-21 17:57 sysnap 阅读(225) 评论(0) 推荐(0)
摘要: x = 1while x <= 10: print(x) x += 1password = ""while password != "3213554": print("input a password: ") password = input()s = ["hello","world","!!"]totals = ""for str in s: totals += strprint(totals)#遍历字典元素map = {"1" 阅读全文
posted @ 2013-11-20 20:26 sysnap 阅读(190) 评论(0) 推荐(0)
摘要: 字典是Python唯一内建的映射类型。键可以是数字,字符串和元组。1 字典的创建方法一:直接创建例如:>>> dict = {'key1':'value1', 20: 80}>>> dict{'key1': 'value1', 20: 80}字典每个键和它的值之间用冒号(:)隔开,项之间用逗号(,)隔开,整个字典用大括号括起来。方法二: dict函数创建例如:items = [['name', 'sysnap'],['age', 30]]d = d 阅读全文
posted @ 2013-11-17 17:49 sysnap 阅读(184) 评论(0) 推荐(0)
摘要: 原文地址http://blog.chinaunix.net/uid-21169302-id-446256.htmlPython-String-Function字符串中字符大小写的变换: * S.lower() #小写 * S.upper() #大写 * S.swapcase() #大小写互换 * S.capitalize() #首字母大写 * String.capwords(S) #这是模块中的方法。它把S用split()函数分开,然后用capitalize()把首字母变成大写,最后用join()合并到一起 * S.title() #只有首字母大写,其余为小写,模块中没有这个方法字符串在输出时 阅读全文
posted @ 2013-11-17 11:51 sysnap 阅读(163) 评论(0) 推荐(0)
摘要: 1 序列在Python中,最基本的数据结构是序列,序列中每个元素被分配一个编号,也称为索引。第一个索引为0,第二个则是1,以此类推。序列中最后一个元素被标为-1,倒数第二个元素被标为-2,以此类推。2 Python内建序列Python包含6种内建序列,分别是列表,元组,字符串,UNICODE字符串,BUFFER对象和XRANGE对象。开始重点关注列表和元组。3列表和元组(序列)列表和元组一个很重要的区别是,列表可以修改,元组则不能被修改。几乎所有情况下列表都可以替代元组,但有一个列外情况,使用元组做为字典的键,在这种情况下,因为键不能被修改,所以不能使用列表。4 序列的通用操作所有序列类型都可 阅读全文
posted @ 2013-11-17 11:02 sysnap 阅读(446) 评论(0) 推荐(0)
上一页 1 ··· 10 11 12 13 14