python字符串

本文通过一个简单的Python脚本示例,介绍了字符串的基本操作方法,包括长度获取、字符访问、重复输出、判断是否全为字母、展示字符串内置方法及帮助信息等。此外,还展示了如何在字符串中使用特殊字符。

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

s = "woxiaoe"

print len(s)

print "s[0] " + s[0] + '\t' + 's[1] ' + s[1];

print "s[-1] " + s[-1] + '\t' + 's[-2] ' + s[-2];

print s*10

 

print 'asS'.isalpha();

print dir(s);

help(s.decode)

msg = '''

adsfsafas"""asdafa"""dddd

sdfs'''

print msg

 

输出

 

7

s[0] w s[1] o

s[-1] e s[-2] o

woxiaoewoxiaoewoxiaoewoxiaoewoxiaoewoxiaoewoxiaoewoxiaoewoxiaoewoxiaoe

True

['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_formatter_field_name_split', '_formatter_parser', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']

Help on built-in function decode:

 

decode(...)

    S.decode([encoding[,errors]]) -> object

 

    Decodes S using the codec registered for encoding. encoding defaults

    to the default encoding. errors may be given to set a different error

    handling scheme. Default is 'strict' meaning that encoding errors raise

    a UnicodeDecodeError. Other possible values are 'ignore' and 'replace'

    as well as any other name registered with codecs.register_error that is

    able to handle UnicodeDecodeErrors.

 

 

adsfsafas"""asdafa"""dddd

sdfs

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值