![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Python
Mryang2333
人生苦短,我用Python。
展开
-
Python None 与 ''(空字符串)
None是一个特殊的常量,有自己的类型:Nonetypeis not None与 !=’ ’起初以为都是表示非空,但是在实际应用时发现不对啊。a = Noneif a != '': print('ok1')if a is not None: print('ok2')这里会输出OK1a = ''if a != '': print('ok1')if a i...原创 2019-01-02 16:29:40 · 10869 阅读 · 1 评论 -
12306模拟登陆Python3.x+cookiejar+request
代码等有时间传到GitHub上去,这里就不展示了,只讲一讲思路。1、cookie的处理其实urllib在open函数内部创建了一个默认的opener对象。然后调用opener.open()函数。但是默认的opener并不支持cookie。那么我们先新建一个支持cookie的opener。urllib中供我们使用的是HTTPCookieProcessor。创建HTTPCookieProcess...原创 2019-01-17 21:29:51 · 481 阅读 · 0 评论 -
with as
Python with as :Context Management Protocol(上下文管理协议):包含方法__enter()和__exit(),支持该协议的对象要实现这两个方法。上下文管理器(Context Manager):支持上下文管理协议的对象,这种对象实现了__enter()__ 和__exit()__ 方法。用下述代码做理解# -*- coding: UTF-8 -*-i...原创 2019-01-25 13:58:28 · 208 阅读 · 0 评论 -
171.Excel表序列号(通过)Python
class Solution: def titleToNumber(self, s): """ :type s: str :rtype: int """ num = 0 for i in range(len(s)-1,-1,-1): num += (ord(s[i]) -...原创 2019-01-28 08:48:49 · 275 阅读 · 0 评论 -
344.反转字符串(通过)Python
最开始想用s.reverse()后来还是写了个替换class Solution: def reverseString(self, s): """ :type s: str :rtype: str """ l = len(s) - 1 for i in range(l): ..原创 2019-01-28 09:24:45 · 213 阅读 · 0 评论 -
461.汉明距离(通过)Python
class Solution: def hammingDistance(self, x, y): """ :type x: int :type y: int :rtype: int """ count = 0 while True: if x == 0 a...原创 2019-01-28 09:26:04 · 973 阅读 · 0 评论 -
561.数组拆分1(通过)Python
class Solution: def arrayPairSum(self, nums): """ :type nums: List[int] :rtype: int """ listNum = list(nums) listNum.sort() sum = 0 ...原创 2019-01-28 09:27:26 · 241 阅读 · 0 评论