
上QQ阅读APP看书,第一时间看更新
4.7 温故知新,学以致用
本章主要讲解了字符串,在本章结束前回顾一下学到的概念。
(1)字符串有哪些基本操作?
(2)字符串格式化的方式有哪些?
(3)字符串比较常用的方法有哪些,该怎么使用?
尝试思考并解决如下问题:
(1)自定义一个字符串,并做字符串的格式化输出。
(2)自定义一个变量,实现整数、浮点数等的格式化输出。
(3)定义一个变量,做格式化输出的对齐,对不齐的部分用空格或其他对应符号填充。
(4)使用find()和index()方法对字符串进行索引,比对两者的异同。
(5)使用join()方法实现多个字符串的连接。
(6)定义一个变量,将变量中的大写字母转化为小写字母、小写字母转化为大写字母。
(7)定义一个变量,对变量特定位置的字符进行替换。
(8)定义一个变量,对变量按指定字符分割,之后将分割结果按指定字符连接。
(9)小智的智商从去年的100分提升到了今年的132分,请计算小智智商提升的百分比,并用字符串格式化显示出“xx.x%”的形式,保留一位小数。
(10)尝试将本章中示例用到的%都换成带'f'前缀的形式做格式化输出。
小程序资源二维码

知识拓展

习题

作业

代码实例

资源包

问答

PPT