zoukankan      html  css  js  c++  java
  • 复习

    # lst = [10, ['hello', 'world'], 20, 30, 100, ['hello', 'world'], 'hello', 'world']
    # lst3 = [True,False,'hello']
    lst[3:] = lst3    
    #[10, ['hello', 'world'], 20, True, False, 'hello']
    #       #切片替换 这应该是魔法吧 
    # 岂不是说,我想加多少就加多少,不超过列表索引的情况下
    
    # str
    a = s.upper()		#全部转换大写,产生一个新的字符串对象
    b = s.lower()		#全部转换小写,产生一个新的字符串对象
    s2 = 'hello,Python'
    print(s2.swapcase())	#字符串所有大写转换为小写.所有小写转换为大写
    print(s2.capitalize())  #把第一个字母转换为大写,其余字母转换为小写
    print(s2.title())		#把每个单词的第一个字母转换为大写,把每个单词的剩余字母转换为小写
    
    # list
    # 类似于魔法的操作了
    #join将列表或元组中的字符串合并为一个字符串
    lst = ['hello','java','Python']
    print(type('|'.join(lst)))  #变成了字符串
    print(''.join(lst))
    
    [start:end:step]
    print(s[-6::-1])# 其中end不写,截取字符串时包括end元素
    # dict
    # 字典生成试
    items = ['Fruits','Books','Others']
    prices = [96,78,85,100,120]
    d = {item.upper():prices  for item,prices in zip(items,prices)} # .upper用法全部转化为大写
    print(d)
    
    
    # 这个表达式也有点东西
    highscore ={}
    for name,score in stuInfo.items():
        if score >90:
            highscore[name]= score
    print(highscore)
    print({name:score for name,score in stuInfo.items() if score >90})
    
    
    # items获取所有的key-value对
    scores = {'张三':100,'李四':98,'王五':45} 
    items = scores.items() # items获取的是字符串
    print(items)  
    print(type(items)) # 这个生成的类型是<class 'dict_items'>
    print(type(tuple(items))) #加元组括号也是 <class 'dict_items'>,用tuple方法则变成了<class 'tuple'>
    print(type([items]))   
    
    '''列表生成式'''
    lst = [i*i for i in range(10)]
    print(lst)
    
    '''集合生成式'''
    s = {i*i for i in range(10)} # 不同之处在于外括号for set and list
    print(s)
    
    努力拼搏吧,不要害怕,不要去规划,不要迷茫。但你一定要在路上一直的走下去,尽管可能停滞不前,但也要走。
  • 相关阅读:
    1438.最小公倍数
    1441.人见人爱A^B
    1083.特殊乘法
    1153.括号匹配
    1089.数字翻转
    1042.coincidence(动态规划求最长公共子序列)
    图的m着色问题pascal程序
    最佳调度问题pascal程序
    试卷批分打表程序
    迷宫问题pascal程序
  • 原文地址:https://www.cnblogs.com/wkhzwmr/p/14846448.html
Copyright © 2011-2022 走看看