Python笔记——字符串

本文详细介绍Python中字符串的基本操作,包括字符串的定义、连接、长度获取、大小写判断及字符计数等实用方法,适合Python初学者快速掌握字符串处理技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Python简单的字符串

Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> 'I am learning Python.'
'I am learning Python.'
>>> x='I am learning Python.'
>>> x
'I am learning Python.'
>>> type(x)
<class 'str'>
>>> "I am learning Pythone."
'I am learning Pythone.'
>>> 'I \'m learning Python.'
"I 'm learning Python."
>>> 

Python实现HelloWord

Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> Fist_word = 'Hello'
>>> Secend_word = 'World!'
>>> print(Fist_word+Secend_word)
HelloWorld!
>>> print(Fist_word+" "+Secend_word)
Hello World!
>>> 

Python字符串方法

1.获取字符串长度
>>> Mom_said = "Tom is good boy"
>>> len(Mom_said)
15
>>> 
2.判断是否都是小写
>>> Mom_said = "Tom is good boy"
>>> Mom_said.islower()
False
>>> 
3.获取某个字符在字符串里面的数量
>>> Mom_said = "Tom is good boy"
>>> Mom_said.count('o')
4
>>> 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值