码迷,mamicode.com
首页 > 其他好文 > 详细

我写的第一期作业

时间:2018-04-03 18:13:01      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:bin   post   pytho   gpo   偶数   lex   upd   元组   pass   

#!/use/bin/python
# -*- conding:utf-8 -*-

#
# 使用while循环输入1 2 3 4 5 6 8 9 10
# i = 1
# while i < 11:
# if i == 7:
# pass
# else:
# print(i)
# i = i + 1
#
# 求1-100的所有数的和
# i = 1
# value = 0
# while i <= 100:
# value = value + i
# i = i + 1
# print(value)
#
# 输出 1-100 内的所有奇数
# i = 1
# while i < 101:
# if i%2 == 1:
# print(i)
# i = i + 1
#
# 输出 1-100 内的所有偶数
# i = 1
# while i <101:
# if i%2 == 0:
# print(i)
# i +=1

# #求1-2+3-4+5 ... 99的所有数的和
# i = 1
# value = 0
# while i < 100:
# if i%2 == 1:
# value = value + i
# else:
# value = value - i
# i = i + 1
# print(value)


# value = ‘jagkdjklajfklnasdlkgnqwlkj‘
# a = value[0:15:3]
# print(a)

# li = [‘eric‘,‘alex‘,‘tony‘]
# for i ,ele in enumerate(li,100):
# print(i,ele)

# user_tuple = (‘alex‘,‘eric‘,‘tongy‘,[‘张三‘,‘李四‘,‘王五‘])
# user_tuple[3][1] = ‘王丽娟‘
# print(user_tuple)
# li = [‘eric‘, ‘alex‘, ‘tony‘]
# for i in range(0,len(li)):
# print(i+1,li[i])

# for i in range(1,11):
# print(i)


# for i in range(10,0,-1):
# print(i)

# li = (11,)
# print(li)

# ------dict,字典----------

# dic = {‘k1‘:‘v1‘,‘k2‘:‘v2‘}
# dic.clear()
# print(dic)
# v = dic.copy()
# print(v)

# dic = {‘k1‘:‘v1‘,‘k2‘:‘v2‘}
# v = dic.get(‘k1‘)
# print(v)
#
# v = dic[0]
# print(v)

# dic = {‘k1‘:‘v1‘,‘k2‘:‘v2‘}
# v = dic.pop(‘k1‘)
# print(dic)
# print(v)

# dic = {‘k1‘:‘v1‘,‘k2‘:‘v2‘}
# k,v = dic.popitem()
# print(dic)
# print(k,v)

# dic = {‘k1‘:‘v1‘,‘k2‘:‘v2‘}
# dic.setdefault(‘k3‘,‘v3‘)
# print(dic)

# dic = {‘k1‘:‘v1‘,‘k2‘:‘v2‘}
# dic.update({‘k3‘:‘v3‘,‘k4‘:‘v4‘})
# print(dic)

# dic = {‘k1‘:‘v1‘,‘k2‘:‘v2‘}
# dic.update({‘k1‘:‘v24‘})
# print(dic)


# dic = dict.fromkeys([‘k1‘,‘k2‘,‘k3‘],[1,])
# print(dic)
# dic[‘k1‘] .append(222)
# print(dic)

##额外的功能,字典的k是不可变类型,元组是可以的,字典不能作为字典的key
# dic = {
# ‘k1‘:‘v1‘,
# ‘k2‘:[1,2,3],
# (1,2,):‘1111‘
# }
# print(dic)
#元组可以作为字典的kye

###############set 集合,补课重复的列表 :可变类型#########
# s1 = {"alex",‘eric‘,‘tony‘,‘李泉‘}
# s2 = {‘alex‘,‘eric‘,‘tony‘,‘六一‘}
# s1.difference_update(s2)
# print(s1)
# #
# v = s1.symmetric_difference(s2)
# print(v)
# s1 = {"alex",‘eric‘,‘tony‘,‘李泉‘}
# # s2 = {‘alex‘,‘eric‘,‘tony‘,‘六一‘}
# s1.discard(‘alex‘)
# print(s1)

# s1 = {"alex",‘eric‘,‘tony‘,‘李泉‘}
# s2 = {‘alex‘,‘eric‘,‘tony‘,‘六一‘}
# v = s1.isdisjoint(s2)
# print(v)

############周末作业##########

我写的第一期作业

标签:bin   post   pytho   gpo   偶数   lex   upd   元组   pass   

原文地址:https://www.cnblogs.com/xg120688/p/8710071.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!