python———first day
阿新 • • 發佈:2018-11-12
print("hello world")
name='I told my friend, "C is my favorite language!"'
second_name=' mygod! end'
second_name=second_name.rstrip() #刪除末尾空白
third_name=' mygod! end'
third_name=third_name.lstrip() #刪除開頭空白
forth_name=' mygod! end'
forth_name=forth_name.strip() #同時剔除字串兩端的空白
end_name= name+" "+second_name
print(name.title())
print(name.upper())
print(name.lower())
print(end_name)
print(second_name)
print(third_name)
print(forth_name)
message = "One of Python's strengths is its diverse community."
print(message) #撇號位於兩個雙引號之間
#eg1
name="erric"
words=", would you liketo learn some Python today?"
print("hello " + name+words)
#eg2
name="WangFong"
print(name.upper()) #大寫
print(name.lower()) #小寫
age = 23
message = "Happy " + str(age) + "rd Birthday!"
print(message) #str將非字串轉換為字串
print(5+3)
print(2*4)
print(24/3)
print(10-2)
#列表
byte=['aa','bb','cc','dd']
print(byte)
print(byte[0])
print(byte[0].title()) #首字母大寫
print(byte[-1])
messages="xiaoming got "
messages=str(messages)+byte[0].title()+"."
print(messages)
names=["liming","xiaoming","lijie","dada"]
print(names)
motorcycles = ['honda', 'yamaha', 'suzuki']
print(motorcycles)
motorcycles[0]='dada' #修改列表元素
print(motorcycles)
motorcycles.append('ssss') #列表中新增元素
print(motorcycles)
motorcycles=[]
motorcycles.append('AAA')
motorcycles.append('BBB')
motorcycles.append('CCC')
print(motorcycles) #建空表再新增元素
motorcycles.insert(1,'100')
print(motorcycles) #在指定位置新增元素
del motorcycles[1]
print(motorcycles) #刪除指定位置元素
popped_motorcycles=motorcycles.pop()
print(motorcycles) #刪除末尾的元素,還能再次引用它
print(popped_motorcycles)
name='I told my friend, "C is my favorite language!"'
second_name=' mygod! end'
second_name=second_name.rstrip() #刪除末尾空白
third_name=' mygod! end'
third_name=third_name.lstrip() #刪除開頭空白
forth_name=' mygod! end'
forth_name=forth_name.strip() #同時剔除字串兩端的空白
end_name= name+" "+second_name
print(name.title())
print(name.upper())
print(name.lower())
print(end_name)
print(second_name)
print(third_name)
print(forth_name)
message = "One of Python's strengths is its diverse community."
print(message) #撇號位於兩個雙引號之間
#eg1
name="erric"
words=", would you liketo learn some Python today?"
print("hello " + name+words)
#eg2
name="WangFong"
print(name.upper()) #大寫
print(name.lower()) #小寫
age = 23
message = "Happy " + str(age) + "rd Birthday!"
print(message) #str將非字串轉換為字串
print(5+3)
print(2*4)
print(24/3)
print(10-2)
#列表
byte=['aa','bb','cc','dd']
print(byte)
print(byte[0])
print(byte[0].title()) #首字母大寫
print(byte[-1])
messages="xiaoming got "
messages=str(messages)+byte[0].title()+"."
print(messages)
names=["liming","xiaoming","lijie","dada"]
print(names)
motorcycles = ['honda', 'yamaha', 'suzuki']
print(motorcycles)
motorcycles[0]='dada' #修改列表元素
print(motorcycles)
motorcycles.append('ssss') #列表中新增元素
print(motorcycles)
motorcycles=[]
motorcycles.append('AAA')
motorcycles.append('BBB')
motorcycles.append('CCC')
print(motorcycles) #建空表再新增元素
motorcycles.insert(1,'100')
print(motorcycles) #在指定位置新增元素
del motorcycles[1]
print(motorcycles) #刪除指定位置元素
popped_motorcycles=motorcycles.pop()
print(motorcycles) #刪除末尾的元素,還能再次引用它
print(popped_motorcycles)