学习笔记(5):零基础掌握 Python 入门到实战-深入浅出字符串(三)

"本文介绍了Python中字符串的常用操作,如`s.index()`方法的用法,以及字符串的分割和连接。通过示例展示了如何查找子串位置,以及如何使用`split()`和`join()`方法处理字符串。同时,讲解了格式化字符串的方法,如`"{0}
摘要由CSDN通过智能技术生成

立即学习:https://edu.csdn.net/course/play/26676/338776?utm_source=blogtoedu

help(s.index) means show the method of s's index

s = "python lesson"

s.index('n') gives 5 

n is the 5th letter in the str

s.index('n', 6) gives 12, means search from the 6th letter till last

a = "I LOVE PYTHON"

if need to split it into words, use split

a.split(" ") gives ['I', 'LOVE', 'PYTHON']

lst = a.split(" ")

"-".join(lst) gives 'I-LOVE-PYTHON'

- is used to put them together

-----------------------------------------

"I like {0} and {1}".format("python","physics")

gives 'I like python and pysics'

"I like {0:10} and  {1:>15}".format(同上)

然后第一个空左对齐第二个右对齐

d的意思是整数

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值