day3-homework

2018-08-22  本文已影响0人  rzlong
username = 'ranzhao'
print("Hello "+username+", would you like to learn some Python today?")
print("Hello %s, would you like to learn some Python today?" % username)

result:
Hello ranzhao, would you like to learn some Python today?
Hello ranzhao, would you like to learn some Python today?
username = 'lucian'
# 首字母大写显示
print(username.capitalize())
# 小写显示
print(username.lower())
# 大写显示
print(username.upper())

result:
Lucian
lucian
LUCIAN
# this sentence is created by rzlong
print('Rzlong said,"Don\'t hesitate! Just do it now."')

result:
Rzlong said,"Don't hesitate! Just do it now."
famous_person = "Rzlong"
message = 'Rzlong said,"Don\'t hesitate! Just do it now."'
print(message)

result:
Rzlong said,"Don't hesitate! Just do it now."
badname = '*****S\thiting\n King*****'
badname2 = '     S\thiting\n King     '
print(badname)
print('------------------------')
# lstrip()函数,剔除字符串左边的空白,也可以括号里带参数(剔除对应的字符)
print(badname.lstrip('*'))
# rstrip()函数剔除字符串右边的空白,也可以括号里带参数(剔除对应的字符)
print(badname.rstrip('*'))
# strip()函数剔除字符串两边的空白,也可以括号里带参数(剔除对应的字符)
print(badname.strip('*'))
print('------------------------')
print(badname2.lstrip())
print(badname2.rstrip())
print(badname2.strip())

reslut:
*****S  hiting
 King*****
------------------------
S   hiting
 King*****
*****S  hiting
 King
S   hiting
 King
------------------------
S   hiting
 King     
     S  hiting
 King
S   hiting
 King
上一篇 下一篇

猜你喜欢

热点阅读