python练习题2

1.

1.1 clear:清空列表
list.remove()
1.2 remove: 删除列表中的给定的对象
list.remove()
1.3将输入的字符垂直输出

1.
for name in "hello":
	print(name)
2.
print("\n".join("Hello World"))

2.英文诗歌统计

find(): 检查是否包含子字符串
str.find(str,beg=0,end=len(string))
beg,and指定索引范围
如果包含返回开始的索引值,否则返回负一
isalpha(): 判断字符串是否只由字母组成
如果是则返回ture,否则返回Fasle
isdigit():检测字符串是否只由数字组成

s1="""All that doth flow we cannot liquid name
Or else would fire and water be the same;
But that is liquid which is moist and wet
Fire that property can never get.
Then'tis not cold that doth the fire put out
But'tis the wet that makes it dio,no doubt."""
x1=len(s1)
x2=s1.find("the")#检查是否包含子字符串
x3=s1.rfind("the")
x4=s1.count("the")
x5=s1.isalpha()
x6=s1.isdigit()
print(x1)
print(x2)
print(x3)
print(x4)
print(x5)
print(x6)

3.前驱后继字符

输入一个字符,求出它的前驱后继字符(按照ASCLL码值排序),并按照从小到大的顺序输出这三个字符对应的ASCII值

s=input()
print(chr(ord(s)-1),s,chr(ord(s)+1))
print(ord(s)-1,ord(s),ord(s)+1)

4.数字排序

将输入的三个数从小到大排列出来

a,b,c=input().split()
if a>b:
    a,b=b,a
if a>c:
    a,c=c,a
if b>c:
    b,c=c,b
print(a,b,c)
`

你可能感兴趣的:(python学习,python,数据结构,算法)