跟我一起学python-字符串

笔记 / 2021-09-15

切片

str = "Hello python"

print(str[:-1])
print(str[1:])

# start end step
print(str[-1:-2:2])

转义

  • R
    -r

字符串运算

  • + 字符串拼接
  • * 字符串重复

是否存在 in


str1 ="hello world"

if "hello" in str1:
    print("yes")
else:
    pritn("no")

字符串大写

upper()


str1 = "hello"

print(str1.upper())

字符串小写

lower()

print(str1.lower())

是否是字母

isalpha()

print(str1.isalpha())

是否是数字

isnum()

print(str1.isnum())

是否是数字字母

isalnum()

print(str1.isalnum())

判断大小

max() min()


print(max(str1),min(str1))

创建字符串

str()

str1 = str(0)

name ='jack'

查看类型

type()

print(type(str1))