python中字符串的基本操作

  1. 使用方法修改字符串
  2. 拼接字符串
  3. 添加空白和换行

\t #空格
\n #换行

  1. 删除空白

name=“mea liu”
name.rstrip()

  1. 使用字符串避免语法错误
  2. Python2中的print语句

print"mea liu" #python2中print语句无需用括号

示例:
1.1 将姓名存到一个变量中,以首字母大写方式显示,输出内容:“Hello,Mea Liu, how is it today?"

name=‘mea liu’
print("Hello, " +name.title()+ “, how is it today?”)

python入门到实践-变量和简单数据类型
参考文献:Python编程:从入门到实践/(美)Eric Matths 著

相关文章:

  • 2021-11-23
  • 2022-12-23
  • 2021-06-07
  • 2021-10-01
  • 2021-11-14
  • 2021-12-19
  • 2021-12-15
  • 2021-11-24
猜你喜欢
  • 2022-03-04
  • 2021-11-22
  • 2021-05-21
  • 2021-11-23
  • 2021-11-29
  • 2021-06-12
  • 2022-01-07
相关资源
相似解决方案