list(map(chr,[*range(ord('A'),ord('Z')+1),*range(ord('a'),ord('z')+1),*range(ord('0'),ord('9')+1),ord('-')]))
''.join((map(chr,[*range(ord('A'),ord('Z')+1),*range(ord('a'),ord('z')+1),*range(ord('0'),ord('9')+1),ord('-')])))
# => 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-'
def validPin(str):
import re
return None!=re.match(r"^(?:(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9]))\S{8,}$",str)
# 或者:
from string import ascii_lowercase as L,ascii_uppercase as U,digits as D
ValidPin = lambda s:all([len(s)>=8,any([i in L for i in s]),any([i in U for i in s]),any([i in D for i in s])])
def level(pin):
import string
dic = {0:"无效",1:"弱",2:"中低",3:"中高",4:"强"}
lib = {1:string.ascii_lowercase,2:string.ascii_uppercase,3:string.digits,4:',.!;?<>'}
pinlevel = 0
for v in lib.values():
for p in pin:
if p in v:
pinlevel += 1
break
return dic[pinlevel * len(pin)>=8] + '密码'
print(level(input()))
def MaxDayMonth(year, month):
days = 31,28+(year%4==0 and year%100!=0 or year%400==0),31,30,31,30,31,31,30,31,30,31
return 0 if (month<1 or month>12) else days[month-1]
def DayofYear(year, month, day):
days = 31,28+(year%4==0 and year%100!=0 or year%400==0),31,30,31,30,31,31,30,31,30,31
return sum(days[:month-1]) + day
class Animal:
def __init__(self, name):
self.name = name
class Cat(Animal):
def __init__(self, name, age):
super().__init__(name) #第一种
#super(Cat,self).__init__(name) #第二种
#Animal.__init__(self,name) #第三种
self.age = age
def cry (self):
print("喵~~~我是{},我{}岁了".format(self.name,self.age))
class Dog(Animal):
def __init__(self, name, color):
super().__init__(name)
#super(Dog,self).__init__(name)
#Animal.__init__(self, name)
self.color = color
def bark(self):
print("汪~~~我是{},我穿着{}的外套".format(self.name,self.color))
cat = Cat('小花', 3)
cat.cry()
dog = Dog('小黄', '红色')
dog.bark()
import string
string.ascii_letters
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
string.ascii_lowercase
'abcdefghijklmnopqrstuvwxyz'
string.ascii_uppercase
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
string.digits
'0123456789'
string.hexdigits
'0123456789abcdefABCDEF'
string.hexdigits
'0123456789abcdefABCDEF'
string.octdigits
'01234567'
string.printable
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&'()*+,-./:;<=>?@[\]^_{|}~ \t\n\r\x0b\x0c' string.punctuation '!"#$%&\'()*+,-./:;<=>?@[\\]^_
{|}~'
string.whitespace
' \t\n\r\x0b\x0c'
s = 'abcdaefgahijkalmn'
string.capwords(s,'a')
'aBcdaEfgaHijkaLmn'
s = 'hello,$a world$b'
t = string.Template(s)
t.substitute({'a':'间隔','b':'!!!'})
'hello,间隔 world!!!'
formatter = string.Formatter()
formatter.format('第{}页/共{}页', *{3,23})
'第3页/共23页'
Python 在问答频道中刷题积累到的小技巧(一)
Python 在问答频道中刷题积累到的小技巧(一)_Hann Yang的博客-CSDN博客
Python 在问答频道中刷题积累到的小技巧(二)
Python 在问答频道中刷题积累到的小技巧(二)_Hann Yang的博客-CSDN博客
Python 在问答频道中刷题积累到的小技巧(三)
Python 在问答频道中刷题积累到的小技巧(三)_Hann Yang的博客-CSDN博客
Python 在问答频道中刷题积累到的小技巧(四)
写代码也有本手俗手之分,而我们要善于发现妙手!_Hann Yang的博客-CSDN博客
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://hannyang.blog.csdn.net/article/details/125270812
内容来源于网络,如有侵权,请联系作者删除!