变量和字符串练习

  断断续续的学了一段时间的python,今天开始系统的学习。在公司看不了视频教程,只能自己看看书,复习一下。

  简单的写了一段代码,主要是练习变量和字符串的。  

#string:artist_intro as confirm _information
what_he_does = ' plays '
his_instrument = 'guitar'
his_name = 'Robert Johnson'
artist_intro = his_name + what_he_does + his_instrument
#print(artist_intro)

#string slice
word = input('please enter your name:')
nick_name = word[0]+word[2:4]+word[-3:-1]
#print(nick_name)

phone_number = input('please enter your phone number:')
hiding_number = phone_number.replace(phone_number[3:9],'*' * 6)
#print(hiding_number)

information = ('your_nickname = %s\nyour_phone_number = %s\nconfirmation_sentence = %s \n')%(word,hiding_number,artist_intro) print('*'*50+'\n'+information+'*'*50+'\n') file = open('test.txt','w') file.write(information) file.close()


 

posted on 2018-10-24 14:43  Aking_Huang  阅读(174)  评论(0编辑  收藏  举报