python基础之字符串
title()方法
name = 'ada lovelace'
print(name.title())
upper()和lower()方法
name = "Ada Lovelace"
print(name.upper())
print(name.lower())
拼接字符串方法
first_name = 'ada'
last_name = "lovelace"
full_name = first_name + " " + last_name
message = "Hello, " + full_name.title() + '!'
print(message)
制表符和换行符
print('\tpython')
print('\npython')
print('python')
删除空白符:
rstrip():删除尾部的空白
lstrip():删除开头的空白
strip():删除首尾两端的空白
数字拼接
age = 23
message = "Happy" + age + "Birthday"
这意味着不同类型是无法拼接的,修改类型如下
age = 23
message = "Happy " + str(age) + " Birthday"
print(message)
注释
#我不会被打印,我只是注释
print('hello world')
本文来自博客园,作者:Harry_666,转载请注明原文链接:https://www.cnblogs.com/harry66/p/13760747.html