python初学习一

#1.切片操作 左闭右开
s='Hello word'
print(s[0:5])
#2.更新字符串
s1='hello word'
s2='python'
print(s1[0:6]+s2)
#3.代表在里面  not in不在里面
print(s2 in s1[0:6]+s2)
#4.回车 \r:打印\r之后的内容
print('hello\rworld')
#5.输出字符串 包括转义字符
print(r'hello\rworld')
print(R'hello\nworld')
#6.字符串的格式化输出
print("我是%s,今天是我第%d天学习%s" % ("wanglei",10,"python"))
#7.字符串的内建函数  查找字符串
s="hello python".find("p")  #第一次出现的位置
print(s)
#8.转化大小写字符
print("Hello Python".lower())
print("Hello Python".upper())
#9.返回字符串长度 _len_() 自然长度
print("Hello Python".__len__())
#10.判断字符串中是否包含空格 有就是false
print("Hello Python".isspace())
#11.capitalize()——首字母大写,其他字母小写
#12 title()——所有单词首字母大写,其他小写
s="HeLLO PYthOn"
print(s.capitalize()) #Hello python
print(s.title()) #Hello Python
s1="'admin','LIST','BAr'"
print(s1.title()) #'Admin','List','Bar'

#13列表
list1=["王哈哈","14","王一一","16"]
print(list1)
print(type(list1))
list1.append("王二二")
list1.append("13")
print(list1+["王三三","20"])
del(list1[3])#删除
print(list1)
list2=[["哈哈","呵呵"],["嗯嗯","哦哦"],["嗯嗯","哦哦"]]
print(len(list2))    #3
print(len(list2[1])) #2
#14移除列表中的元素
l=list2.pop(1)
print(l)
print(list2)

#给自己的题目 公交车上有建国,爱国,车通过天安门时,王哈哈上车;车通过天安门1时,爱国下车,王一一上车;车通过天安门2时,建国下车,王二二上车。显示出车停车之后车上人员情况
station = input("请输入车站名称:")
peop_list=["建国","爱国"]
bus_list=["天安门","天安门1","天安门2"]
for bus in bus_list:
    if bus == "天安门":
     peop_list.append("王哈哈")
    if bus == "天安门1":
     peop_list.remove("爱国")
     peop_list.append("王一一")
    if bus == "天安门2":
     peop_list.remove("建国")
     peop_list.append("王二二")
    if station == bus:
        break
print(peop_list)
posted @ 2020-01-08 11:00  我是王哈哈w  阅读(160)  评论(0编辑  收藏  举报