python代码统计200行

li=['alex',100,True,[1,2,3],{'name':'太白'},(22,32)]
print(li[0],type(li[0])) #alex <class 'str'>
print(li[1],type(li[1])) #100 <class 'int'>
print(li[:4]) #['alex', 100, True, [1, 2, 3]]
print(li[::2]) #['alex', True, {'name': '太白'}]
print(li[-1:-4:-2]) #[(22, 32), [1, 2, 3]]
l1=['alex','wusir','taibai','egon','景女神','文周老师','日天']
l1.append('小甲鱼')
print(l1) #['alex', 'wusir', 'taibai', 'egon', '景女神', '文周老师', '日天', '小甲鱼']
print(l1.append([1,2,3])) #None
name_list=['张安','李四']
while 1:
    username=input('请输入新员工的姓名:').strip()
    if username.upper()=='Q':
        break
    name_list.append(username)
print(name_list)
l1.insert(1,'大宝')
print(l1) #['alex', '大宝', 'wusir', 'taibai', 'egon', '景女神', '文周老师', '日天']
l1.extend('abc')
print(l1) #['alex', 'wusir', 'taibai', 'egon', '景女神', '文周老师', '日天', 'a', 'b', 'c']
l1.extend([11,22,33,44])
print(l1) #['alex', 'wusir', 'taibai', 'egon', '景女神', '文周老师', '日天', 11, 22, 33, 44]
l1.extend(['alex','ss'])
print(l1) #['alex', 'wusir', 'taibai', 'egon', '景女神', '文周老师', '日天', 'alex', 'ss']
l1.pop(0)
ret=l1.pop(0)

print(ret)  #alex
print(l1) #['wusir', 'taibai', 'egon', '景女神', '文周老师', '日天']
l1.remove('alex')
print(l1) #['wusir', 'taibai', 'egon', '景女神', '文周老师', '日天']
l1.clear()
print(l1) #[]
del l1[1::2]
print(l1) #['alex', 'taibai', '景女神', '日天']
del l1
print(l1) #报错
l1[2]='男神'
l1[0]='屌丝'
print(l1) #['屌丝', 'wusir', '男神', 'egon', '景女神', '文周老师', '日天']
l1[:2]='ssssss'
print(l1) #['s', 's', 's', 's', 's', 's', 'taibai', 'egon', '景女神', '文周老师', '日天']
l1[0:4]=[11,22,33,44,55,66,77]
print(l1) #[11, 22, 33, 44, 55, 66, 77, '景女神', '文周老师', '日天']
l1[:3:2]='ss' #['s', 'wusir', 's', 'egon', '景女神', '文周老师', '日天']
print(l1)
print(l1[0]) #alex
for i in l1:
    print(i)
print(len(l1))#7
print(l1.count('alex'))#1
l2=[5,6,7,1,4,3,2,9]
l2.sort()
print(l2) #[1, 2, 3, 4, 5, 6, 7, 9]
l2.sort(reverse=True)
print(l2) #[9, 7, 6, 5, 4, 3, 2, 1]
l2.reverse()
print(l2) #[9, 2, 3, 4, 1, 7, 6, 5]
l3 = ['alex', 'wusir', ['taibai', 99, 'ritian'], 20]
s2=l3[0][2]
print(s2) #e
l3[1]=l3[1].upper()
print(l3) #['alex', 'WUSIR', ['taibai', 99, 'ritian'], 20]
l3[2].append('文周')
print(l3) #['alex', 'wusir', ['taibai', 99, 'ritian', '文周'], 20]
l3[0]=l3[0].capitalize()
print(l3) #['Alex', 'wusir', ['taibai', 99, 'ritian'], 20]
l3[2][1]=l3[2][1]+1
print(l3) #['alex', 'wusir', ['taibai', 100, 'ritian'], 20]
tu1=['alex',100,True,[1,2,3],{'name':'太白'},(22,33)]
print(tu1[0]) #alex
print(tu1[:3]) #['alex', 100, True]
tu1 = ('a', 'b', '太白', 3, 666)
for i in tu1:
    print(i)
print(tu1.index('太白')) #2
print(tu1.count('a')) #
tu1=('alex',100,True,[1,2,3],{'name':'太白'},(22,33))
print(tu1[0])
print(tu1[:3])
for i in tu1:
    print(i)
for i in range(1,11):
    print(i)
for i in range(1,22,2):
    print(i)
for i in  range(10,1,-1):
    print(i)
l1=('alex','wusir','taibai','egon','景女神','文周老师','日天')
for i in range(0,len(l1)):
    print(i)
for i in l1:
    print(l1.index(i))
s1='alex'
print('a' in s1) #True
print('al' in s1) #True
print('alx' in s1) #False
l1=('alex','wusir','taibai','egon','景女神','文周老师','日天')
print('alex' in l1)  #True
print('alex' not in l1) #False
print(['alex','alex']  in l1) #False
dic={'太白':
         {'name':'太白金星','age':22,'sex':'男'}
     'python':
     ['小甲鱼','小鱿鱼','小鲤鱼','小绵羊']
}
dic=dict((('one',1),('two',2),('three',3)))
print(dic) #{'one': 1, 'two': 2, 'three': 3}
dic=dict(one=1,two=2,three=3)
print(dic) #{'one': 1, 'two': 2, 'three': 3}
dic=dict({'one':1,'two':2,'Three':3})
print(dic) #{'one': 1, 'two': 2, 'Three': 3}
dic={[1,2,3]:'alex',666}
print(dic)#报错
dic={1:'alex',1:'太白',2:'wusir'}
print(dic) #{1: '太白', 2: 'wusir'}
dic={'name':'太白','age':22}
dic['sex']='男'
print(dic) #{'name': '太白', 'age': 22, 'sex': '男'}
dic['age']=23
print(dic) #{'name': '太白', 'age': 23}
dic.setdefault('hobby','球类运动')
print(dic) #{'name': '太白', 'age': 22, 'hobby': '球类运动'}
dic.setdefault('hobby')
print(dic) #{'name': '太白', 'age': 22, 'hobby': None}
dic.setdefault('age',44)
print(dic) #{'name': '太白', 'age': 22}
ret=dic.pop('age')
print(ret)#22
print(dic)#{'name': '太白'}
ret=dic.pop('hobby','没有此键')
print(ret) #没有此键
print(dic) #{'name': '太白', 'age': 22}
dic.clear()
print(dic) #{}
del dic['age']
print(dic) #{'name': '太白'}
del dic
print(dic) #报错
del dic['age1']
print(dic)  #报错
dic['name']='alex'
print(dic)#{'name': 'alex', 'age': 22}
dic={'name':'太白','age':18,'hobby_list':['直男','钢管','开车']}
print(dic['hobby_list']) #['直男', '钢管', '开车']
l1=dic.get('hobby_list')
print(l1) #['直男', '钢管', '开车']
l1=dic.get('hobby_list1')
print(l1) #None
l1=dic.get('like','没有此键')
print(l1)
print(list(dic.keys())) #['name', 'age', 'hobby_list']
for key in dic.keys():
    print(key)
for key in dic:
    print(key)
print(dic.values()) #dict_values(['太白', 18, ['直男', '钢管', '开车']])
print(list(dic.values())) #['太白', 18, ['直男', '钢管', '开车']]
print(tuple(dic.values())) #('太白', 18, ['直男', '钢管', '开车'])
for value in dic.values():
    print(value)
print(dic.items()) #dict_items([('name', '太白'), ('age', 18), ('hobby_list', ['直男', '钢管', '开车'])])
for i in dic.items():
    print(i)
for key,value in dic.items():
    print(key,value)
a=18
b=333
a,b=b,a
print(a,b) #333 18
dic = {'name_list': ['王双', 'alex', '孙飞', 'taibai'],
        1: {'name': 'taibai', 'age': 18, 'sex': '男'},
        (1, 2): [100, {'ip':'192.168.1.1', 'port': 3306}]
        }
dic['name_list'].append('司徒大人')
print(dic)
dic['name_list'][1]=dic['name_list'][1].upper()
print(dic)
dic[1].setdefault('weight',75)
print(dic)
dic[1]['name']='alex'
print(dic) #{'name_list': ['王双', 'alex', '孙飞', 'taibai'], 1: {'name': 'alex', 'age': 18, 'sex': '男'}, (1, 2): [100, {'ip': '192.168.1.1', 'port': 3306}]}
dic[(1,2)][1].pop('port')
print(dic)
dic = {"name":"jin","age":18,"sex":"male"}
dic.update(a='666',b='000')
print(dic) #{'name': 'jin', 'age': 18, 'sex': 'male', 'a': '666', 'b': '000'}
dic.update(name='alex')
print(dic) #{'name': 'alex', 'age': 18, 'sex': 'male'}
name='alex'
name1='alex'
print(id(name),id(name1)) #2274912617392 2274912617392
s1='alex'
s2='alex'
print(s1 is s2) #True
s1=''
s2=''
print(s1 is s2) #True
b1=b'alex'
b2=b1.upper()
s1='alex'
print(b1,type(b1)) #b'alex' <class 'bytes'>
print(b2,type(b2)) #b'ALEX' <class 'bytes'>
print(s1,type(s1)) #alex <class 'str'>
s1='太白'
s2='alex'
b1=s1.encode('utf-8')
print(b1) #b'\xe5\xa4\xaa\xe7\x99\xbd'
b2=s2.encode('gbk') #b'\xe5\xa4\xaa\xe7\x99\xbd'
b1=b'\xcc\xab\xb0\xd7'
s2=b1.decode('gbk')
print(s2) #太白

  

posted @ 2020-06-03 23:54  菜鸟鸭  阅读(232)  评论(0编辑  收藏  举报