Python 练习二

# 判断text文件上传成功,其他文件上传失败
list1 = [ "文档1.text","图片.png","文档2.pdf","文档3.doc","文档4.text"]

for i in list1:
    if i.endswith(".text"):
        print("%s上传成功"%i)
    else:
        print("%s上传失败"%i)
# 将字符串 "abcd" 转成大写
str1 = 'abcd'
print(str1.upper())
# 计算字符串 "cd" 在 字符串 "abcd"中出现的位置
str2 = 'abcd'
print(str2.index('cd'))
# 字符串 "a,b,c,d" 请根据逗号切割字符串,分割后的结果是什么类型的?
str3 = "a,b,c,d"
print(str3.split(','))
print(type(str3.split(',')))
# "Python is good" 请将字符串里的 Python 替换成 Java
str4 = "Python is good"
print(str4.replace("Python","Java"))
#  "python_62_3.py.xxx" 获取字符串.py 前面的部分
str5 = "python_62_3.py.xxx"
print(str5[:str5.find(".py")])
# "this is a book" 请用程序取出该英文句子的第一个单词并打印
str6 = "this is a book"
print(str6.split(' ')[0])
# "this is a book" 请用程序判断该字符串是否以 apple 结尾
str7 = "this is a book"
print(str7.endswith('apple'))
# "This IS a book" 请将字符串里的大写字符转成小写字符
str8 = "This IS a book"
print(str8.lower())
# "this is a book\n" 字符串的末尾有一个回车符,请将其删除
str9 = "this is a book\n"
print(str9.strip())
# "hello world" 请找到该字符串最后一个"l"出现的位置
str10 = "hello world"
i = str10.count("l")
print(str10.index("l",i+1))
# 现有任意一个字符串,判断该字符串的首字母是否大写
str11 = input("请输入一个字符串:")
if str11[0].isupper():
    print("该字符串的首字母是大写")
else:
    print("该字符串的首字母不是大写")
# 有一个英文句子,比如 'hello world hello python',将其中的每一个单词首字母大写,得到'Hello World Hello Python'
# 方法一
str12 = 'hello world hello python'
print(str12.title())

# 方法二-replace
str12 = 'hello world hello python'
str13 = str12.split(' ')
str14 = []
for i in str13:
    i.replace(i[0],i[0].upper())
    str14.append(i.replace(i[0],i[0].upper()))
print(' '.join(str14))

# 方法三-capitalize
str12 = 'hello world hello python'
str13 = str12.split(' ')
str14 = []
for i in str13:
    str14.append(i.capitalize())
print(' '.join(str14))
# 给定一个英文句子比如"hello python" 将句子中的单词位置反转为
str15 = "hello python"
str16 = str15.split(' ')
print(' '.join(str16[::-1]))
# 有一个 url:https://iruance.com?username=admin&password=123456&sex=GG&from=China,将url中所有
# 参数值取出并装在一个列表中,如[username=admin', 'password=123456', 'sex=GG', 'from=China']
url1 = 'https://iruance.com?username=admin&password=123456&sex=GG&from=China'
print(url1.split("?")[1].split("&"))
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值