检查并判断密码字符串的安全强度 import string def check(pwd): #密码必须至少包含六个字符 if not isinstance(pwd,str) or len(pwd)<6: return 'noot suitable for password' #密码强度等级与包含字符种类的对应关系 d = {1:'weak',2:'below middle',3:'above middle',4:'strong'} #分别用来标记pwd是否含有数字.小写字母.大写字母.指定的标点
类方法string.upper(str)需要引入string模块,实例方法str.upper()不需要引入string模块 无与伦比的列表解析功能 # coding=utf-8 # 列表解析 print [i * 2 for i in [8, -2, 5]] print [i for i in range(8) if i % 2 == 0] 在FF的javascript1.7就实现了相同的语法( Array Comprehension) var evens = [i for (i in rang
最近在学习python,随手做些记录,方便以后回顾 #字符串是不可再改变的序列aa='abcd'#aa[2:]='ff' #报错,不可直接赋值#字符串格式化:使用格式化操作符即百分号%来实现print 'price of aggs: $%d'%42mm='hello'nn='world'print '%s go %s'%(mm,nn)#String 模板字符串格式化:用传递的关键字参数(foo)替换字符串中的$foos=Template('$x is $x')print s.substitute
字符串 #字符串操作# 对应操作:# 1.重复输出字符串# print('hello'*2)# 2.[],[:]通过索引获取字符串中字符,这里和列表的切片操作是相同的,具体内容见列表#print('hellworld'[2:])# 3.in,成员运算符,如果字符串中包含给定的字符返回true#print('el' in 'hello')# 4.%,格式字符串# print('alex is a good teacher')# print('%s is a good teacher' % 'ale
配置环境:python 3.6 python编辑器:pycharm 代码如下: #!/usr/bin/env python #-*- coding: utf-8 -*- def strCase(): "字符串大小写转换" print("演示字符串大小写转换") print("演示字符串S赋值为:' ThIs is a PYTHON '") S = ' ThIs is a PYTHON ' print("大写转换成小写:\tS.low
OSX从Pthon 2.7升级到3.8 1,官网下载最新安装包安装 2,执行认证文件command 3,执行设置path command 4,设置默认python 在terminal里运行open ~/.bash_profile,打开~/.bash_profile,直接修改文件保存,重启Terminal. source ~/.bash_profile # Setting PATH for Python 3.8 # The original version is saved in .bash_p
1.字符串引用变量 name="Jasper" age=23 msg="my name is %s,my age is %s"%(name,age) print(msg) 运行结果:my name is Jasper,my age is 23 除了上面方法可以直接引用 变量,还可以使用format函数 msg="my name is {name},my age is {age}" msg2=msg.format(name="huqian
----------------------------------------------实际应用中的其他常见的字符串方法 >>>line = "the knights who say ni!\n">>>line.restrip(); 清楚末尾的空格the knights who say ni!>>>line.upper() 大小写转换THE KNIGHTS WHO SAY NI!\n>>>line.is