《Python编程从入门到实践》
第二章 字符串
print("Hello Python world!")
msg1 = "hi"
print(msg1)
msg2 = 'hi2'
print(msg2)
字符串连接
msg3 = msg1 + ' ' + msg2
print(msg3)
‘’和“”“”
msg4 = "hello 'may' "
print(msg4)
msg5 = 'hello "may" '
print(msg5)
name = "ada lovelace"
首字符大写
print(name.title())
全部大写
print(name.upper())
全部小写
print(name.lower())
制表符
print("\tPython")
换行符
print("\nPython")
fav_language = ' python '
print(fav_language)
去除后面空白字符
print(fav_language.rstrip())
去除前面空白字符
print(fav_language.lstrip())
去除前后空白字符
print(fav_language.strip())
网友评论