当前位置: 首页 > news >正文

打开网站搜索做效果图的素材网站

打开网站搜索,做效果图的素材网站,湖南品牌网站建设,成都视觉设计公司对于python而言#xff0c;一切事物都是对象#xff0c;对象是基于类创建的#xff0c;对象继承了类的属性#xff0c;方法等特性1.int首先#xff0c;我们来查看下int包含了哪些函数#python3.xdir(int)#[__abs__, __add__, __and__, __bool__, __ceil__, __class__, __de…对于python而言一切事物都是对象对象是基于类创建的对象继承了类的属性方法等特性1.int首先我们来查看下int包含了哪些函数#python3.xdir(int)#[__abs__, __add__, __and__, __bool__, __ceil__, __class__, __delattr__, __dir__, __divmod__, __doc__, __eq__, __float__, __floor__, __floordiv__, __format__, __ge__, __getattribute__, __getnewargs__, __gt__, __hash__, __index__, __init__, __int__, __invert__, __le__, __lshift__, __lt__, __mod__, __mul__, __ne__, __neg__, __new__, __or__, __pos__, __pow__, __radd__, __rand__, __rdivmod__, __reduce__, __reduce_ex__, __repr__, __rfloordiv__, __rlshift__, __rmod__, __rmul__, __ror__, __round__, __rpow__, __rrshift__, __rshift__, __rsub__, __rtruediv__, __rxor__, __setattr__, __sizeof__, __str__, __sub__, __subclasshook__, __truediv__, __trunc__, __xor__, bit_length, conjugate, denominator, from_bytes, imag, numerator, real, to_bytes]#python 2.xdir(int)#[__abs__, __add__, __and__, __class__, __cmp__, __coerce__, __delattr__, __div__, __divmod__, __doc__, __float__, __floordiv__, __format__, __getattribute__, __getnewargs__, __hash__, __hex__, __index__, __init__, __int__, __invert__, __long__, __lshift__, __mod__, __mul__, __neg__, __new__, __nonzero__, __oct__, __or__, __pos__, __pow__, __radd__, __rand__, __rdiv__, __rdivmod__, __reduce__, __reduce_ex__, __repr__, __rfloordiv__, __rlshift__, __rmod__, __rmul__, __ror__, __rpow__, __rrshift__, __rshift__, __rsub__, __rtruediv__, __rxor__, __setattr__, __sizeof__, __str__, __sub__, __subclasshook__, __truediv__, __trunc__, __xor__, bit_length, conjugate, denominator, imag, numerator, real]#__abs__() 绝对值输出num 1result num.__abs__()print(result)num -1result num.__abs__()print(result)__abs__() 绝对值输出1 num -12 result num.__add__(2)34 print(result)56 #打印结果将输出 1__add__加法1 num 52 result num.__and__(2)3 print(result)45 #打印输出为06 #0 0 0 0 0 1 0 1 57 #0 0 0 0 0 0 1 0 28 #相同位为1则为1由于没有相同位所以5 2结果为0__and__ 与运算1 #以下结果输出都是True2 num 113 print(num.__bool__()) #True45 num -116 print(num.__bool__()) #True78 #以下结果输出都是 False9 num 010 print(num.__bool__()) #False1112 num None13 num False14 print (num.__bool__()) #False__bool__ 布尔值#通过divmod函数可以实现将一个int类型对象除以另一个int对象得到一个两个元素的列表#列表左边为除尽取整的值第二个元素为取模的余数num 9result num.__divmod__(2)print(result)#输出(4,1)__divmod__ 除法取整取模num 2result num.__eq__(3)print(result)#打印结果为False#2 3 结果为假result num.__eq__(2)print(result)#打印结果为True#2 2 结果为真__eq__ 比较运算符__eq__ 比较运算符num 9print(num.__float__())#打印结果为 9.0__float__ 转换为浮点数num int(181)result num.__floordiv__(9)print(result)#打印输出20#地板除 //取整__floordiv__地板除//__floordiv__地板除//num int(181)result num.__getattribute__(bit_length)print(result)#打印输出 #说明该数据类型num存在bit_length这个属性可以用于判断对象是否拥有某种属性__getattribute__获取对象属性num int(181)print(num.__ge__(111))#打印输出结果为True#因为181大于111所以结果为真该属性用于判断大于等于该属性自身的方法结果将返回真否则为假__ge__ 比较运算num 181print(int.__invert__(num))#打印输出-182num -180print(int.__invert__(num))#打印输出179num -181print(int.__invert__(num))#打印输出180__invert__ 非~运算num -181result num.__le__(111)print(result)#打印输出结果为True#当传人参数与对象本身相比较只要对象小于或者等于传人的参数则结果为真否则为假__le__ 小于等于num -181result num.__lshift__(1)print(result)#打印输出结果为-362 即-181 *( 2**1)result num.__lshift__(2)print(result)#打印输出结果为-724 ,即-181*(2**2)#当传入参数大于等于0时且对象本身不能为0首先参数本身为2的指数幂运算然后再与对象本身相乘结果则为左移最终结果__lshift__左移运算num -181print(num.__lt__(11))#打印输出结果为True#凡是对象比传入的参数小则结果为真否则结果为假__lt__小于num -181print(num.__mod__(3))#打印输出结果为2因为181除以3等于60余数为2所以结果为2__mod__取模运算num 181print(num.__mul__(2))#打印输出结果为362即181*2的结果__mul__ 乘法运算num -181print(int.__neg__(num))#打印结果为181即-(-181)结果为181__neg__一元运算减法num 181print(num.__ne__(181))#打印结果为Falseprint(num.__ne__(11))#打印结果为True#凡是传入参数与对象本身不相等则结果为真否则为假__ne__ 不等于比较num 18print(num.__or__(7))#打印输出结果为23#0 0 0 1 0 0 1 0 18#0 0 0 0 0 1 1 1 7#0 0 0 1 0 1 1 1 23位的或运算凡是相同位有一位为真即为1则结果为真即1然后所以最终结果为23__or__ 或|运算num 9print(num.__pow__(2))#打印输出结果为81即9**2__pow__ 幂运算num 6print(num.__rdivmod__(3))#返回结果(0,3) 左边为余数右边为整除的结果__rdivmod__ 与divmod返回的结果相反#python 2.7num 1print(num.__sizeof__())#打印输出结果为24个字节说明一个int类型默认就在内存中占用了24个字节大小#python3.5num 1print(num.__sizeof__())#打印输出结果为28个字节说明一个int类型数据默认在内存中占用了24个字节大小__sizeof__ 计算数据类型占用内存大小num int(1111)result num.__str__()print(type(result))#打印输出结果为#将int类型转换为str数据类型__str__ int转换成strnum int(9)print(num.__sub__(2))#打印输出结果为7#对象本身减去传入参数得到最终的返回值__sub__ 减法运算num 11print(num.__truediv__(3))#打印输出结果为3.6666666666666665#返回的数据类型为float浮点型__truediv__ 真除num 10print(num.__xor__(6))#0 0 0 0 1 0 1 0 10#0 0 0 0 0 1 1 0 6#0 0 0 0 1 1 0 0 12#同位比较都是0则为假都是1则为假一真一假为真__xor__ 异或^运算num 5print(num.bit_length())#打印输出结果为3#0 0 0 0 0 1 0 1 长度为3位bit_length 显示数据所占位长度num 2.3 - 2.5jresult num.real #复数的实部print(result) #打印输出2.3result num.imag #复数的虚部print(result) #打印输出2.5jresult num.conjugate() #返回该复数的共轭复数print(result) #打印输出(2.32.5j)conjugatenum 5print(num.__format__(20))#表示5前面讲话有20个空格__format__ 格式化输出print(int.from_bytes(bytesb1, byteorderlittle)#打印输出 49 即将字符1转换为十进制from_bytes 字符转换十进制num 2result num.to_bytes(5,byteorderlittle)print(result)#打印输出b\x02\x00\x00\x00\x00for i inresult:print(i)#打印输出2\n0\n0\n0\n0#\n表示回车to_bytes int转换为字节2.str1 #python3.52dir(str)3 #[__add__, __class__, __contains__, __delattr__, __dir__, __doc__, __eq__, __format__, __ge__, __getattribute__, __getitem__, __getnewargs__, __gt__, __hash__, __init__, __iter__, __le__, __len__, __lt__, __mod__, __mul__, __ne__, __new__, __reduce__, __reduce_ex__, __repr__, __rmod__, __rmul__, __setattr__, __sizeof__, __str__, __subclasshook__, capitalize, casefold, center, count, encode, endswith, expandtabs, find, format, format_map, index, isalnum, isalpha, isdecimal, isdigit, isidentifier, islower, isnumeric, isprintable, isspace, istitle, isupper, join, ljust, lower, lstrip, maketrans, partition, replace, rfind, rindex, rjust, rpartition, rsplit, rstrip, split, splitlines, startswith, strip, swapcase, title, translate, upper, zfill]45 #python2.76dir(str)7 #[__add__, __class__, __contains__, __delattr__, __doc__, __eq__, __format__, __ge__, __getattribute__, __getitem__, __getnewargs__, __getslice__, __gt__, __hash__, __init__, __le__, __len__, __lt__, __mod__, __mul__, __ne__, __new__, __reduce__, __reduce_ex__, __repr__, __rmod__, __rmul__, __setattr__, __sizeof__, __str__, __subclasshook__, _formatter_field_name_split, _formatter_parser, capitalize, center, count, decode, encode, endswith, expandtabs, find, format, index, isalnum, isalpha, isdigit, islower, isspace, istitle, isupper, join, ljust, lower, lstrip, partition, replace, rfind, rindex, rjust, rpartition, rsplit, rstrip, split, splitlines, startswith, strip, swapcase, title, translate, upper, zfill]strA helloprint(strA.__add__(world))#输出hello world__add__ 字符串拼接strA helloprint(strA.__contains__(h))#Trueprint(strA.__contains__(hex))#False__contains__ 包含判断strA helloprint(strA.__eq__(hello))#Trueprint(strA.__eq__(hellq))#False__eq__ 字符串比较strA helloprint(strA.__getattribute__(__add__))##判断对象是否包含传入参数的属性__getattribute__获取对象属性strA helloprint(strA.__getitem__(0))#输出下标为0的字符 h#超出下标会报错的__getitem__获取对应字符strA helloprint(strA.__getnewargs__())#打印输出 (hello,)#将字符类型转换为元组方式输出__getnewargs__转换成元组strA helloprint(strA.__ge__(HELLO))print(strA.__ge__(Hello))print(strA.__ge__(hello))#以上结果都为True,print(strA.__ge__(hellq))#以上结果为假__ge__ 字符串比较strA Helloprint(strA.__gt__(HellO))#打印输出True#字符串比较的是传入的参数每个字符首先得包含对象其次如果字符串之间比较大写比小写大如果传入参数都为大写且对象也都为大写那么结果为假,字符串比较首先比较的是字符串是否相同不相同则为假再次每个字符进行比较只要前面有一位大于对方则不继续比较了#比如 HelLo与HEllo,首先两个字符串都是一样的然后再比较第一位第一位也一样再比较第二位大写比小写大所以第二个字符串大就不会继续比较下去了__gt__ 字符串大于判断strA helloprint(strA.__hash__())#-7842000111924627789__hash__ 生成一个临时的hash值strA helloresult strA.__iter__()for i inresult:print(i)#打印输出#h#e#l#l#o__iter__ 字符串迭代strA helloprint(strA.__len__())#打印输出结果为5__len__ 判断字符串长度strA Helloprint(strA.__le__(ello))#True#字符串小于运算比较先比较对象是否包含传入参数当包含则再比较相同位的字母大小字母比小写字母大当前面有一位比较出谁大谁小了则不再继续比下去了__le__小于等于strA helloprint(strA.__lt__(ello))#True#字符串小于比较与小于等于比较类似唯一一点是小于比较时对象与传入的参数大小写不能完全一样__lt__小于strA helloprint(strA.__mul__(3))#hellohellohello#打印结果将输出三个hello__mul__ 乘法运算__le__小于等于strA helloprint(strA.__ne__(HEllo))#True#字符串不等于运算比较凡是对象与传入参数只要有一个字母大小写不一样则为真否则为假__ne__ 不等于比较strA HELLOprint(strA.zfill(6))#0HELLO当传入的参数长度比对象长度大时多余的长度则以0进行填充zfill 以0填充strA hELlo1112123print(strA.upper())#HELLO#将所有的字母转换为大写upper 字母转换大写print(hello world.title())#Hello World#每个单词首字母大写输出且单词的第二位后面都会变成小写如helLO,最终会格式化为Hellotitle 标题print(hEllO.swapcase())#HeLLo#将原来的大小字母转换成小写字母小写转换成大小字母swapcase 大小写转换print(hello world.strip())#hello world#将字符串两边的空格去掉strip 去除字符串两边的空格print(hello.startswith(h))#Trueprint(hello.startswith(h,1))#False#startswith这个函数可以指定起始位置进行判断字符是否存在startswith 字符串是否存在该字符print(hello\nworld.splitlines())#[hello,world]#splitlines默认以\n换行符进行分割字符最终返回一个列表splitlines 以换行符分割字符串print(hello world.split())#[hello,world]print(hello world.split(\n))#[hello world,]#默认以空格分割字符串可以指定分隔符split 默认以空格分割字符print(hello world.rstrip())#hello world#打印将会把world后面的空格去除rstrip 去除右边的空格print(hello world.rpartition(he))#(, he, llo world )#只返回传入参数且存在字符串里的字符然后组合成一个新的元组rpartition 返回字符串的一部分print(hello world.rjust(20))#hello world#默认以空格填充从左到最后一个单词d结尾一个长度为20也就是说h前面有9个空格print(hello world.rjust(20,))#hello world#这里以‘’填充对比上面可以看的更具体前面有9个被用来填充rjust 向右偏移print(hello world.rindex(wo))#6#通过查找字符串wo获取该字符串在hello world 里面的下标位置这里从左往右数第七个位置字符串的下标默认从0开始所以返回6#当找不到时则抛出异常rindex 查找下标strA hello 123table1 str.maketrans(123,我很好)print(strA.translate(table1))#hello 我很好#将字符串里面的123通过table进行翻译成对应的值table1的123长度必须和‘我很好长度对应’strA hello 12table1 str.maketrans(123,我很好)print(strA.translate(table1))#hello 我很translate 翻译print(hello.rfind(e))#1print(hello.rfind(ee))#-1如果找到则结果为对应的下标否则返回-1rfind 从左到右查找print(hello world.replace(e,o))#hollo world#将字符串里面所有的e替换成o区分大小写replace 字符串替换print(hello world.rpartition(el))#(h, el, lo world)#效果与rpartition相似partition 截取字符串table1 str.maketrans(123,我很好)print(table1)#{49: 25105, 50: 24456, 51: 22909}首先传入的必须是两个参数且长度相等#返回结果将是一个字典类型每一个字符串将会映射到第二个参数的相同位置的字符串上#当这里存在三个参数时第三个参数必须是一个字符串类型且整个字符串将被映射成NonestrA hello 1233飒飒table1 str.maketrans(123,我很好,飒飒)print(strA.translate(table1))print(table1)#以下为输出结果#hello 我很好好#{49: 25105, 50: 24456, 51: 22909, 39122: None}#这个字典的值将被映射成unicode值如49表示unicode的1maketrans 翻译表print(hello world.lstrip())#hello world将hello左边空格去除lstrip 去除左边的空格print(HELLo22.lower())#hello22#将所有字母转换为小写lower 转换小写print(hello world.ljust(20,))#hello world#从右向左开始进行填充总长度为20ljust 右填充print(.join((hello,world)))#helloworld#通过一个字符串去与join里面的一个迭代器里的字符串进行联结生存一个新的字符串join 生存一个字符串print(Hello.isupper())print(HELLO1.isupper())#False#True#判断所有的字母是否都是大小是则返回真否则假isupper 是否全部大小print(Hello.istitle())print(Hello world.istitle())#True#False#判断每个单词首字母是否大写是则为真否则为假istitle 是否是标题print(hello.isspace())print( .isspace())#False#True#判断内容是否为空格isspace 是否是空格print(hello world.isprintable())print(\n.isprintable())#True#False#由于换行符是特殊字符不可见所以不能被打印结果为假issprintable 是否可以被打印print(111.isnumeric())print(壹.isnumeric())print(1q.isnumeric())#True#True#False#True包含unicode数字全角数字(双字节)罗马数字汉字数字isnumeric 是否是数字print(Hello.islower())print(hello.islower())#False#True#判断字母是不是都是小写是则为真否则为假islower 是否是小写print(def.isidentifier())print(hello.isidentifier())print(2a2.isidentifier())#True#True#False#用来检测标识符是否可用也就是说这个名字能不能用来作为变量名是否符合命名规范如果符合则为真#通常会结合keyword.iskeyword()这个方法去在做判断是否是关键字防止因命名不规范导致某些内置功能不可用isidentifierprint(hello.isdigit())print(111e.isdigit())print(壹.isdigit())print(121.isdigit())#False#False#False#True#unicode数字全角数字(双字节)byte数字罗马数字都为真isdigit 是否是数字print(11.isdecimal())print(壹.isdecimal())print(11d.isdecimal())##True#False#False#只有全部为unicode数字全角数字(双字节),结果才为真isdecimal 是否是数字print(hee.isalpha())print(Hello.isalpha())print(1212.isalpha())print(hhee1.isalpha())#True#True#False#False#当结果都是字母则为真否则为假isalpha 是否是字母print(hew11.isalnum())print(HHH.isalnum())print(112.isalnum())print(q.isalnum())print(!!~d.isalnum())#True#True#True#False#False#当结果为任意数字或字母时结果为真其他字符为假isalnum 是否为数字或字母print(hello.index(e))print(hello.index(el))print(hello.index(el,1))#1#1#1#通过查找制定的字符获取对应字符串的下标位置可以指定起始位置第3个事咧则表示从下标1开始查找包括下标1的位置如果指定end的结束位置查找是不包括end的位置本身index 通过字符查找下标print(hello.find(h,0))print(hello.find(h,1))#0#-1#find是从下标0位置开始找起包含开始的位置0如果有结束的位置不包含结束位置查找到则显示具体下标位置否则显示1find查找字符串下标print(hello{0}.format(world))print(hello{0}{1}.format(world,python))print(hello{name}.format(nameworld))#hello world#hello world python#hello worldformat 格式化输出字符串print(hello\tworld.expandtabs(tabsize8))#hello world 指定制表符长度为8expandtabs 制表符长度print(hello.endswith(lo,3))#True#判断结束字符是否为lo默认从下标0开始查找包含下标0的位置endswith 判断结束字符print(我好.encode())print(hello.encode())#print(hela!~~!\xe2lo.encode(gbk,errorsstrict))print(b\xe6\x88\x91\xe5\xa5\xbd.decode(utf-8))#b\xe6\x88\x91\xe5\xa5\xbd#bhello#我好#将字符串进行编码最终返回以b开头的编码格式encode 编码print(heelloe.count(e,1,2))#1#表示从开始下标1包括下标1位置查找字符e,结束位置为下标2不包括结束位置#统计结果为1count 统计相同的字符print(aaa.center(22,))#aaa#表示将字符aaa的位置显示在长度为22的中间位置默认是空格方式填充这里以号填充方便演示效果注意由于22-3(字符本身3个长度),剩余的并不能整除所以先整除的整数部分作为公共的填充内容剩余的填充到末尾center 中心显示print(hDasdd23ellAo.casefold())#hdasdd23ellao#将字符串里面所有的字母都转换为小写输出casefold 字母转换小写print(hEello World.capitalize())#Heello world#这个方法会将整个字符串的第一个字母大写其余都是小写输出如果第一个字符串不是字母则只将其余字母转换成小写capitalize 首字母大写3.list#定义一个列表b [a,hello,python,1]#查看列表的内置方法dir(b)#2.x 输出 [__add__, __class__, __contains__, __delattr__, __delitem__, __delslice__, __doc__, __eq__, __format__, __ge__, __getattribute__, __getitem__, __getslice__, __gt__, __hash__, __iadd__, __imul__, __init__, __iter__, __le__, __len__, __lt__, __mul__, __ne__, __new__, __reduce__, __reduce_ex__, __repr__, __reversed__, __rmul__, __setattr__, __setitem__, __setslice__, __sizeof__, __str__, __subclasshook__, append, count, extend, index, insert, pop, remove, reverse, sort]#3.x输出[__add__, __class__, __contains__, __delattr__, __delitem__, __dir__, __doc__, __eq__, __format__, __ge__, __getattribute__, __getitem__, __gt__, __hash__, __iadd__, __imul__, __init__, __iter__, __le__, __len__, __lt__, __mul__, __ne__, __new__, __reduce__, __reduce_ex__, __repr__, __reversed__, __rmul__, __setattr__, __setitem__, __sizeof__, __str__, __subclasshook__, append, clear, copy, count, extend, index, insert, pop, remove, reverse, sort]b.append(tail) #在列表末尾追加一个元素tailb.count(python) #统计列表中有多少个相同的元素pythonb.extend(how) #在列表后面追加三个字符串h,o,wb.index(python) #显示元素‘python’的索引这里将输出2b.insert(1,niubi) #在索引为的位置插入元素niubi及原来的元素从1往后加1b.pop() #将列表最后一个元素删除b.remove(niubi) #删除指定元素即将指定的niubi元素删除b.reverse() #将列表的元素由原来的从左到右顺序变成从右到左方式排序b.sort() #将列表按照assci顺序排序,注意3.x版本的排序是不能同时有多个数据类型一起排序的。b.clear() #将列表b清空,这个方法只有3.x才有a b.copy() #将列表b复制给a貌似没有发现有什么其它特别之处相对于直接使用a b方式这个属性也是只有3.x版本才有4.tuple#例如,定义一个元组a (a,hello,python,1)#查看元组的内置方法dir(a)#将会输出一个列表形式的方法名称#2.x 输出[__add__, __class__, __contains__, __delattr__, __doc__, __eq__, __format__, __ge__, __getattribute__, __getitem__, __getnewargs__, __getslice__, __gt__, __hash__, __init__, __iter__, __le__, __len__, __lt__, __mul__, __ne__, __new__, __reduce__, __reduce_ex__, __repr__, __rmul__, __setattr__, __sizeof__, __str__, __subclasshook__, count, index]#3.x输出 [__add__, __class__, __contains__, __delattr__, __dir__, __doc__, __eq__, __format__, __ge__, __getattribute__, __getitem__, __getnewargs__, __gt__, __hash__, __init__, __iter__, __le__, __len__, __lt__, __mul__, __ne__, __new__, __reduce__, __reduce_ex__, __repr__, __rmul__, __setattr__, __sizeof__, __str__, __subclasshook__, count, index]#元组提供了两个公有方法给我们使用a.count(hello) #统计元组里面有多少个相同的元素hello很显然这里只有1个所以输出结果为 1a.index(hello) #返回元素hello的索引位置python的索引位置是从0开始的所以这里的‘hello’元素的索引是1而不是2.#元组的访问方式a[1] #显示下标为1的元素因为元组的下标是从0开始的所以会显示元素helloa[2] #这里会显示第python这个元素a[0:1] #显示元素从位置0(包括0) 到1(不包括1),即显示aa[0:2] #显示元素从位置0(包括0)到2(不包括2)即显示(a,hello)a[-1] #显示倒数第一个元素即1a[-2] #显示倒数第二个元素即pythona[:-2] #显示元素从位置0(包括)到位置倒数第二个(不包括倒数第二个)之前的元素都显示出来即(a,hello)a[-2:] #显示元素从位置倒数第二个(包括)到最后一个(包括)即(python,1)a[0:4:2] #该方式先将前面的[0:4]条件先筛选出来然后再进行后面的:2即每隔一位取一个值所以这里将显示(a,python)5.dict#python3.5dir(dict)#[__class__, __contains__, __delattr__, __delitem__, __dir__, __doc__, __eq__, __format__, __ge__, __getattribute__, __getitem__, __gt__, __hash__, __init__, __iter__, __le__, __len__, __lt__, __ne__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __setitem__, __sizeof__, __str__, __subclasshook__, clear, copy, fromkeys, get, items, keys, pop, popitem, setdefault, update, values]#python2.xdir(dict)#[__class__, __cmp__, __contains__, __delattr__, __delitem__, __doc__, __eq__, __format__, __ge__, __getattribute__, __getitem__, __gt__, __hash__, __init__, __iter__, __le__, __len__, __lt__, __ne__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __setitem__, __sizeof__, __str__, __subclasshook__, clear, copy, fromkeys, get, has_key, items, iteritems, iterkeys, itervalues, keys, pop, popitem, setdefault, update, values, viewitems, viewkeys, viewvalues]food {1:apple,2:banana}print(food)food.clear()print(food)#{2: banana, 1: apple} 正常打印结果#{} 调用字典函数clear打印结果clear 清空字典food {1:apple,2:banana}newfoodfood.copy()print(newfood)#{1: apple, 2: banana} 打印输出copy 浅拷贝字典food {1:apple,2:banana}print(food.fromkeys((w),(2,5)))print(food)#{w: (2, 5)}#{2: banana, 1: apple}#注意这个操作并不会改变字典的数据值仅仅是返回一个新字典fromkeys 返回一个新字典food {1:apple,2:banana}print(food.get(22))print(food.get(1))print(food.get(22,neworange))print(food.get(1,neworange))print(food)#None 如果没有这个key将返回一个默认值none#apple 如果能能查到key则显示对应的值#neworange 如果查不到则显示默认的值#apple 如果能查到key只显示key对应的值否则使用默认的值#{1: apple, 2: banana} get不会改变字典内容get 获取字典值food {1:apple,2:banana}print(food.items())#dict_items([(1, apple), (2, banana)]) 将字典的键存放在一个元组对应的值也放在另一个元组里面返回items 获取字典的key,valuesfood {1:apple,2:banana}print(food.keys())#dict_keys([2, 1])keys 以元组形式返回字典键food {1:apple,2:banana}result food.pop(1)print(result)print(food)#apple 将被删除的键对应的值返回#{2: banana} 打印更新后的字典pop 删除指定的键值对food {1:apple,2:banana}print(food.popitem())print(food)#(1, apple) 随机删除键值对#{2: banana} 返回删除后的字典popitem 随机删除键值对food {1:apple,2:banana}print(food.setdefault(3,orange))print(food)#orange 默认的值#{3: orange, 2: banana, 1: apple} 打印字典setdefault 设置默认的键值对food {1:apple,2:banana}goods {1:TV,22:Computer}print(food.update(goods))print(food)#None#{2: banana, 1: TV, 22: Computer} 如果存在对应的key则更新value,否则新增键值对update 更新字典food {1:apple,2:banana}print(food.values())#dict_values([apple, banana])values 以列表形式返回字典的值6.数据类型转换列表转换成元祖#定义一个列表a [a, b, c]#通过tuple函数将列表转换成元组我们把新生成的元组赋值给cc tuple(a)print(c)#结果显示(a, b, c)说明我们现在已经把列表转换成一个新的元组了。元组转换成列表#由于元组上不可更改的当我们想变更时该怎么办呢只能将元组转换成列表将其修改后再转换成元祖形式#定义一个元组a (a,b,c)#使用list函数将元组转换成列表然后赋值给一个新的变量名为c这样c就有list函数所有属性了c list(a)print(c)#打印结果输出为 [a, b, c]通过这种方法如果我们想在现有的元组基础上做操作修改可以先转换成列表列表是考验直接修改元素的修改完后我们再将它转换成元组重新赋值给a7.文件处理7.1文件操作语法file object open(file_name,[access_mode],[buffering])·file_name:file_name参数是一个字符串值包含要访问的文件的名称。·access_mode:access_mode确定该文件已被打开即模式。读、写等追加可能值的一个完整 列表在下表中给出。这是可选的参数默认文件访问模式是读(r)·buffering:如果缓冲值被设置为0没有缓冲将发生。如果该缓冲值是1将在访问一个文件进行缓冲。如果指定的缓冲值作为大于1的证书那么缓冲操作将被用指定缓冲器大小进行。这是可选的参数。7.2文件访问模式模式描述r以只读方式打开文件文件指针放在文件开头这个是默认模式rb以二进制格式读取文件指针放在文件开头r以读取和写入方式打开文件文件指针在文件开头rb以二进制读取和写入方式打开文件w以只写方式打开文件如果文件存在则覆盖文件内容不存在则创建一个新文件wb打开文件以二进制方式写入文件存在则覆盖不存在则创建新文件w以写入和读取方式打开文件如果文件存在则覆盖不存在则创建新文件wb以二进制方式写入和读取文件存在则覆盖现有文件不存在则创建新文件a以追加方式写入文件末尾如果不存在则创建该文件ab以二进制格式追加在文件末尾不存在则创建该文件a以追加和读取方式打开文件如果文件存在文件指针在文件的末尾如果不存在则创建新文件并写入和读取7.3文件的操作示例open_file open(/tmp/file.txt,r) #以读取和写入方式打开文件open_file.write(hello\n) #写入内容加上换行符open_file.close()#打开文件后不做操作需要关闭#文件操作有以下几种方法#2.x 方法 [__class__, __delattr__, __doc__, __enter__, __exit__, __format__, __getattribute__, __hash__, __init__, __iter__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__, close, closed, encoding, errors, fileno, flush, isatty, mode, name, newlines, next, read, readinto, readline, readlines, seek, softspace, tell, truncate, write, writelines, xreadlines]#3.x 方法[_CHUNK_SIZE, __class__, __del__, __delattr__, __dict__, __dir__, __doc__, __enter__, __eq__, __exit__, __format__, __ge__, __getattribute__, __getstate__, __gt__, __hash__, __init__, __iter__, __le__, __lt__, __ne__, __new__, __next__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__, _checkClosed, _checkReadable, _checkSeekable, _checkWritable, _finalizing, buffer, close, closed, detach, encoding, errors, fileno, flush, isatty, line_buffering, mode, name, newlines, read, readable, readline, readlines, seek, seekable, tell, truncate, writable, write, writelines]
http://www.pierceye.com/news/350435/

相关文章:

  • 广东网站建设公司排名网页设计模板网站免费
  • 佛山网站建设小程序注册营业执照申请
  • 网站建设文案策划鞍山兼职吧
  • 手机投资网站合肥seo优化排名公司
  • 上海网站制作公司的排名药品网站如何建设
  • 模板网站建设包括哪些wordpress怎么加关键词和描述
  • 温岭专业自适应网站建设响应式网站 模版
  • 高端包装设计优化 英语
  • 佛山新网站建设方案笔记本做网站服务器
  • c 企业网站开发杭州百度人工优化
  • 瑞安公司网站建设wordpress 主题和插件下载失败
  • 茶楼网站模板wordpress后台图
  • 做网站的流程方法wordpress 导航栏 排序
  • 当当网书店网站建设案例照片制作相册
  • 手机网站空间wordpress改微博系统
  • 东莞阿里网站设计泰安网站营销推广
  • 网站可以换域名吗北京建站公司兴田德润很好
  • 烟台做网站建设大宗商品交易平台是什么
  • 网站安全建设目标昆明网站制作企业
  • 个人网站更换域名企业网站建设套餐价格
  • 什么网站做海宁的房产好自己做软件 做网站需要学会哪些
  • 品牌网站建设浩森宇特软件工程师年薪多少
  • 做网站没有数据库ppt模板制作免费
  • 网站建设代码合同重庆住房和城乡建设部网站的打印准考证
  • 天气网站建设wordpress yasaer
  • 无忧网络网站建设响应式网页设计技术有哪些
  • 非常好的网站建设公司上海如何批量建站
  • 珠海市官网网站建设品牌深圳创业补贴去哪里申请
  • 建立传媒公司网站wordpress 农场主题
  • 如何用ps做网站导航条劳保用品 技术支持 东莞网站建设