fork download
  1. # 给定字符串
  2. text = "Hello|Python|World"
  3.  
  4. #提取并拼接
  5. parts = text.split("|") # 分割得到 ['Hello','Python','World']
  6. result1 = parts[0] + " " + parts[2] # 取第1个和第3个,用空格拼接
  7. print(result1)
  8. replaced =text.replace("Python","AI") # 将 Python 替换为 AI
  9. result2 = replaced.upper() # 转换为大写
  10. print(result2)
Success #stdin #stdout 0.09s 14084KB
stdin
Standard input is empty
stdout
Hello World
HELLO|AI|WORLD