美文网首页Python四期爬虫作业
【Python爬虫】- 第3天字符串练习题

【Python爬虫】- 第3天字符串练习题

作者: 悟道叔 | 来源:发表于2017-08-13 17:44 被阅读0次
一、定义字符串变量

1.请定义三个字符串a,b,c值分别为 I,like, python

2.请将上面三个变量合并输出 'I like python'
a='i'
b='like'
c='python'
print(a,b,c)
二、定义一个变量 s= ' sdghHhf '

1.请先将变量s的空白符去掉 赋值给新变量s1 打印输出
s = ' sdghHhf '
s1=s.strip()
print(s1)
2.请分别将s1变为全部大写(命名s2),小写(命名s3),打印输出s2,s3
s = ' sdghHhf '
s1=s.strip()
s2=s1.upper()
s3=s1.lower()
print(s2,s3)
3.请查找s1中h最先出现的位置 赋值给s4 打印输出
s = ' sdghHhf '
s1=s.strip()
s4=s1.find('h')
print(s4)

三、定义一个变量x='I {} pyhon'

请用两种方法将x中的字符串{}修改为 like 并分别赋值给两个变量x1,x2 打印输出
x='I {} pyhon'
x1='I {} python'.format('like')
x2=x.replace('{}','like')
print(x1,x2)
四、定义一个变量capital='人民币100万元'

1.请打印一下capital的长度
capital='人民币100万元'
print(len(capital))
2.请用python语言判断capital是否是数字
capital='人民币100万元'
print(capital.isdigit())

相关文章

网友评论

    本文标题:【Python爬虫】- 第3天字符串练习题

    本文链接:https://www.haomeiwen.com/subject/pfserxtx.html