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.  
  9. replaced = text.replace("Python", "AI") # 将 Python 替换为 AI
  10. result2 = replaced.upper() # 转换为大写
  11. print( result2 )
Success #stdin #stdout 0.07s 14152KB
stdin
Standard input is empty
stdout
Hello World
HELLO|AI|WORLD