python———first day

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) 
 

猜你喜欢

转载自blog.csdn.net/qq_33301482/article/details/81036823