2-3 個性化消息: 將用戶的姓名存到一個變量中,并向該用戶顯示一條消息。顯示的消息應(yīng)非常簡單拇舀,如“Hello Eric, would you like to learn some Python today?”截碴。
name = 'hcy'
print('Hello %s,Would you like to learn some Python today?'% name)
2-4 調(diào)整名字的大小寫: 將一個人名存儲到一個變量中憔辫,再以小寫、大寫和首字母大寫的方式顯示這個人名金顿。
name = 'hcy'
print(name)
print(name.upper())
print(name.title())
2-5 名言: 找一句你欽佩的名人說的名言臊泌,將這個名人的姓名和他的名言打印出來。輸出應(yīng)類似于下面這樣(包括引號):Albert Einstein once said, “A person who never made a mistake never tried anything new.
print('Albert Einstein once said, “A person who never made a mistake never tried anything new.”')
2-6 名言2: 重復(fù)練習(xí)2-5揍拆,但將名人的姓名存儲在變量famous_person 中渠概,再創(chuàng)建要顯示的消息,并將其存儲在變量message 中嫂拴,然后打印這條消息
famous_person = 'Albert Einstein'
word = '“A person who never made a mistaka never tried anything new.”'
message = '%sonce said:%s' % (famous_person,word)
print(message)
print('========')
2-7 剔除人名中的空白: 存儲一個人名播揪,并在其開頭和末尾都包含一些空白字符。務(wù)必至少使用字符組合"\t" 和"\n" 各一次筒狠。 打印這個人名猪狈,以顯示其開頭和末尾的空白。然后辩恼,分別使用剔除函數(shù)lstrip() 雇庙、rstrip() 和strip() 對人名進行處理谓形,并將結(jié)果打印出來。
name = '\t\nhcy\n'
print(name)
name1 = name.lstrip()
print(name1)
name2 = name1.rstrip()
print(name2)
name3 = name.strip()
print(name3)
運行結(jié)果