|
发表于 2019-12-15 09:32:49
|
显示全部楼层
《零基础入门学习Python》视频下载地址:传送门
测试题:
0. 还记得如何定义一个跨越多行的字符串吗(请至少写出两种实现的方法)?
\n
""" """
1. 三引号字符串通常我们用于做什么使用?
输出一段长字符串
2. file1 = open('C:\windows\temp\readme.txt', 'r') 表示以只读方式打开“C:\windows\temp\readme.txt”这个文本文件,但事实上这个语句会报错,知道为什么吗?你会如何修改?
3. 有字符串:str1 = '<a href="http://www.fishc.com/dvd" target="_blank">鱼C资源打包</a>',请问如何提取出子字符串:'www.fishc.com'
>>> str2 =str1.split("/")
>>> str2[2]
4. 如果使用负数作为索引值进行分片操作,按照第三题的要求你能够正确目测出结果吗?
>>> str2 =str1.split("/")
>>> str2[-3:-2]
5. 还是第三题那个字符串,请问下边语句会显示什么内容?
>>> str1[20:-36]
空
复制代码
6. 据说只有智商高于150的鱼油才能解开这个字符串(还原为有意义的字符串):str1 = 'i2sl54ovvvb4e3bferi32s56h;$c43.sfc67o0cm99'
str1[::3]
password = input("请输入需要检查的密码组合:")
special= ("~!@#$%^&*()_=-/,.?<>;:[]{}|\\\\")
# and or special in password )
if password.isalnum() and len(password)<=8 :
print("低级密码")
elif not password.isnumeric() and (not password.isalpha() or special in password ) and len(password)>8:
print("中级密码")
elif not password.isnumeric() and not password.isalpha() and special in password and len(password)>16:
print("高级密码")
else:
print("输入不正确")
字符串的方法
capitalize() 将字符串第一个字符改为大写
casefold()将字符串所有字符改为小写
center(width) 将字符串居中,用空格来填充width的新字符
ljust(width)返回一个左对齐的字符串,并使用空格填充至长度为 width 的新字符串
rjust(width)返回一个右对齐的字符串,并使用空格填充至长度为 width 的新字符串
zfill(width) 返回长度为width的字符串,原字符串右对齐,前面用0填充
count(sub[,start[,end]) 返回 sub 在字符串里边出现的次数,start 和 end 参数表示范围,可选
|
|