a = 100
b = "hello siddim.com" 或者 b = 'hello siddim.com.cn'
single_str = 'a我是单引号括起来的字符串' type(single_str) # type 查看数据类型 double_str = "a我是双引号括起来的字符串" type(double_str) # type 查看数据类型
name = 'siddimAdmin' position = '讲师' address = '北京市海淀区中关村科技园' print('--------------------------------------------------') print("姓名:%s"%name) print("职位:%s"%position) print("公司地址:%s"�dress) print('--------------------------------------------------')
输出: -------------------------------------------------- 姓名:siddimAdmin 职位:讲师 公司地址:北京市海淀区中关村科技园 --------------------------------------------------
userName = input('请输入用户名:') print("用户名为:%s"%userName) password = input('请输入密码:') print("密码为:%s"%password)
执行结果: 请输入用户名:sd 用户名为:sd 请输入密码:123456 密码为:123456
mystr="welcome to python world and just do it"; print(mystr.find("java",0)); 结果是:-1
mystr="welcome to python world and just do it"; print(mystr.index("java",0));
mystr="welcome to python world and just do it"; print(mystr.count("o")); 结果:5
mystr="welcome to python world and just do it"; print(mystr.replace("o","9")); 结果: welc9me t9 pyth9n w9rld and just d9 it
mystr="welcome to python world and just do it"; print(mystr.split("o")); 结果: ['welc', 'me t', ' pyth', 'n w', 'rld and just d', ' it']
mystr.capitalize() mystr="welcome to python world and just do it"; print(mystr.capitalize()) 结果: Welcome to python world and just do it
mystr="welcome to python world and just do it"; print(mystr.title()) 运行结果: Welcome To Python World And Just Do It
mystr="welcome to python world and just do it"; print(mystr.startswith("H")) 输出: False
mystr="welcome to python world and just do it"; print(mystr.endswith("t")) 输出:True
mystr="welcome to python world and just do it"; print(mystr.lower()) 输出: welcome to python world and just do it
mystr="welcome to python world and just do it"; print(mystr.upper()) 输出: WELCOME TO PYTHON WORLD AND JUST DO IT
mystr="python"; print(mystr.ljust(15))
mystr="python"; print(mystr.rjust(15))
mystr="python"; print(mystr.center(15))
mystr=" python"; print(mystr.lstrip()) 输出: python
mystr=" python "; print(mystr.rstrip()) 输出: python
mystr=" python Java "; print(mystr.strip()) 输出: python Java
mystr="welcome to python world and just do it"; print(mystr.rfind("o")) 输出: 34
mystr="welcome to python world and just do it"; print(mystr.rindex("t")) 输出: 37
mystr="welcome to python world and just do it"; print(mystr.partition("and")) 输出: ('welcome to python world ', 'and', ' just do it')
mystr="welcome to python world and just do it"; print(mystr.rpartition("o")) 输出: ('welcome to python world and just d', 'o', ' it')
mystr="welcome\n to python world\n and\njust do it"; print(mystr.splitlines()) 输出: ['welcome', ' to python world', ' and', 'just do it']
mystr="welcome to python world and just do it"; print(mystr.isalpha()) 输出: False
mystr="welcome to python world and just do it"; print(mystr.isdigit()) 输出:False
mystr.isalnum()
mystr.isspace()
mystr="welcome to python world and just do it"; print(mystr.join("AI")) 输出: Awelcome to python world and just do itI
names = "AIforAll"; print("0--",names[0]) print("1--",names[1]) print("2--",names[2]) print("3--",names[3]) print("4--",names[4]) print("5--",names[5]) print("6--",names[6])
0-- A 1-- I 2-- f 3-- o 4-- r 5-- A 6-- l
names = "AIforAll"; print(names[0:3]) # 取 下标0~2 的字符 输出: AIf
names = "AIforAll"; print(names[0:3]) # 取 下标0~2 的字符 print(names[0:5]) # 取 下标为0~4 的字符 print(names[3:5]) # 取 下标为3、4 的字符 print(names[2:]) # 取 下标为2开始到最后的字符 print(names[1:-1]) # 取 下标为1开始 到 最后第2个 之间的字符 输出: AIf AIfor or forAll IforAl
double_str = " 我是等待链式 调用处理的字符串 \n" double_str.replace(" ", "").strip() '我是等待链式调用处理的字符串'
join capitalize casefold center count encode endswith expandtabs find format format map index isalnum isalpha isascii isdecimal isdigit isidentifier islower isnumeric isprintable isspace istitle isupper ljust lower Istrip maketrans partition removeprefix removesuffix replace rfind rindex rjust rpartition rsplit rstrip split splitlines startswith strip swapcase title translate upper zfill