Python字符串

Python字符串学习并记录

执行如下代码:

first_name = "ada"
last_name = "lovelace"
print(first_name.title())
print(first_name.upper())
print(first_name.lower())

Albert_Einstein = 'Albert Einstein once said,"A person who never made a mistake never tried anything new."'
print(Albert_Einstein)

famous_person = "Albert_Einstein"
message = f'{famous_person} once said,"A person who never made a mistake never tried anything new."'
print(message)


name = "\tPython\n"
print(name)
name1 = name.rstrip()
print(name1)
name2 = name.lstrip()
print(name2)
name3 = name.strip()
print(name3)
print()

返回如下代码:

Ada
ADA
ada
Albert Einstein once said,"A person who never made a mistake never tried anything new."
Albert_Einstein once said,"A person who never made a mistake never tried anything new."
	Python

	Python
Python

Python

打印字符串首字母大写
.title()
打印字符串全部大写
.upper()
打印字符串全部小写
.lower()

清除字符串后面的内容默认空格
.rstrip()
清除字符串前面的内容默认空格
.lstrip()
清除字符串前后的内容默认空格
.strip()

点赞

发表评论

电子邮件地址不会被公开。必填项已用 * 标注