******
20230213
******
# 字符串的用法——合并
What_he_does = ' plays '
his_instrument = 'guitar'
his_name = 'Robert Johnson'
artist_intro = his_name + What_he_does + his_instrument
print(artist_intro)
******
# 不同数据类型的转换与合并
num = 2
String = '2'
#temp = num + String
#print(temp)
num2 = int(String)
temp2 = num + num2
print(temp2)
******
# 不同数据类型的转化合并(相加)与相乘
words ='words ' * 3
print(words)
words2 = 'a loooooooong word'
num = 12
string = 'bang! '
total = string * (len(words2) - num)
print(total)
******
# 字符串的分片与索引_1
name= 'My name is Mike'
print(name[0])
print(name[-4])
print(name[5])
print(name[-10])
print(name[0:8])
print(name[7:14])
print(name[:8])
print(name[7:])
******
# 字符串的分片与索引_2
word = 'friends'
find_the_evil_in_your_friends = word[0] + word[2:4] + word[-3:-1]
print(find_the_evil_in_your_friends)
url = 'http://www.site.cn/1234567890abcdefghijklmnopqrstuvwxyz.jpg'
file_name = url[-8:]
print(file_name)
******
# 字符串的方法
phone_number = '1386-666-0006'
hiding_number = phone_number.replace(phone_number[:9],'*' *9)
print(hiding_number)
search = '168'
num_a = '1386-168-0006'
num_b = '1681-222-0006'
print(search + ' is at ' + str(num_a.find(search)) + ' to ' + str(num_a.find(search) + len(search)) + ' of num_a')
print(search + ' is at ' + str(num_b.find(search)) + ' to ' + str(num_b.find(search) + len(search)) + ' of num_b')
print(str(num_b.find(search)) + str(num_b.find(search) + len(search)))
******
# 字符串格式化符
city = input("write down the name of city:")
url = "http://apistore.baidu.com/microservice/weather/weather?citypinyin={}".format(city)
url2 = "http://ForTest{}".format(city)
print(url)
print(url2)
******