Python入门-- 字符串对象的学习

Python入门-- 字符串对象的学习

1.字符串是 Python 中最常用的数据类型。我们可以使用引号( ’ 或 " )来创建字符串。
2、定义字符串
	单引号  双引号 三引号
3、字符串的常用方法
	>>> s="haha"
	>>> dir(s)
['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'capitalize', 'casefold', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isascii', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']



	 'capitalize'		# 将字符串的首字母大小
	 'center'			# 将字符串居中,第二个参数表示填充的符号
	 'count'				# 统计字符串中出现字符或者字符串次数
	 'encode'			# 该方法就可以将字符串转换为字节
	 						以后建议大家进行编码转换的时候统一使用utf-8
							注意:编码和解码一定要使用同一个标准!!!
	'decode'			#与它对应的是字节的decode(解码)
	'endswith'		# 判断字符是否以xx结尾
	'startswith'		# 判断字符串是否以xxx开头
	'find'					# 查找字符串中某个字符或者字符串第一次
							# 出现的位置,注意:如果不存在,则返回-1
	'rfind'				# 找最后一个

	'index'				# 查找字符串中某个字符或者字符串第一次
							# 出现的位置,注意:如果不存在,则抛出异常
	'rindex'				# 找最后一个
	'format'			# python3推出新的一种格式化字符串的方式
	'join'					# 用来拼接字符串,注意参数是一个可迭代对象
	'split'				# 分割字符串
	'rsplit'				#

	'lower'			# 转小写
	'upper'			# 转大写 
	'title'		# 转换字符串为一个符合标题的规则
	'strip'		# 清除字符串两边的空格
	'rstrip'			# 清除右边的空格
	'lstrip'			# 清除左边空格
	'replace'			# 替换字符串

		
	# 如下判断是不是的方法,只要会用即可
	istitle			# 判断字符串是不是标题
	isspace			# 判断是不是空白字符
	islower			# 判断是不是小写字母
	isupper			# 判断是不是大字母
	isalnum			# 判断是不是有字母和数字组成
	isalpha			# 判断是不是有字母组成
	isdigit			# 判断是不是数字组成
4、字符串切片
		https://www.jianshu.com/p/15715d6f4dad
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值