Python字符串学习

def printName():
    "Test Funciton"
    print("Hello Poem")

printName()

print(printName.__doc__)

输出

Hello Poem
Test Funciton

函数的文档字符串

字符串的操作


str_poem = ''' 山一程,水一程,身向榆关那畔行,夜深千帐灯。
风一更,雪一更,聒碎乡心梦不成,故园无此声。'''

str_motto = 'I wish the progress bar of my life could move more slowly that I can spare no effort to walk to the end instead of running after time'

print(str_poem[0:10])
print(str_poem[0:30])


#求字符串长度 len
len_num = len(str_motto)
print(len_num)

#切片会创建新对象
print(str_motto[2:100])
print(str_motto[100:2:-1])

#倒数的第一个字符
print(str_motto[-1])
#倒数的第三个字符
print(str_motto[-3:])

strNums = [1, 2, 3, 100, -1]
print(min(strNums))
print(max(strNums))
print(max(str_motto)) # ISCC码最大值ASCII码
print(sum(strNums))

isLower = str_motto.islower()
print(isLower)

扫描二维码关注公众号,回复: 4721118 查看本文章

猜你喜欢

转载自blog.csdn.net/moonlightpeng/article/details/85328746