当前位置: 代码迷 >> 综合 >> Byte-of-python笔记代码2:module.py
  详细解决方案

Byte-of-python笔记代码2:module.py

热度:87   发布时间:2023-10-20 03:35:45.0

#-*-coding:utf-8-*-
###import导入某模块
# import sys
#
# for i in sys.argv:
#     print(i)
# print("\n\nThe Pythonpath",sys.path,"\n")# ##from math import sqrt,应该尽量避免使用from...import ...
# from math import sqrt
# print("16的开方={0}".format(sqrt(16)))# ##_name_
# if __name__ =="__main__":
#     print("{0}这是我自己运行的".format(__name__))
# else:
#     print("{0}这个模块不是我的,是导入的!!".format(__name__))# import sys
# dir()# ##列表[a,b,c,......],列表是可变的
#
# a=[1,2,89,4,50,6]
# print("我又一个长度为{0}的列表,开心啊!".format(len(a)))
# print("他们分别是:",end='')
# for i in a:
#     print("{0},".format(i),end='')
#
# a.append(10)
# print("\n我又加了一个数,他们分别是:",end='')
# for i in a:
#     print("{0},".format(i),end='')
#
# a.sort()
# print("\n我把他们排了个序,他们分别是:",end='')
# for i in a:
#     print("{0},".format(i),end='')
#
# del a[0]
# print("\n我删了第一个数,他们分别是:",end='')
# for i in a:
#     print("{0},".format(i),end='')##元组:(a,b,c,......),元组不可被改变,元组中可以包含元组,形成二次元组# zoo=("a","b","c")
# print("zoo这个元组的长度为:{0}".format(len(zoo)))
#
# # new_zoo="a","b","d",zoo
# # print("我不用括号,也可以定义元组,嘿嘿,他的长度为:{0}".format(len(new_zoo)))
# # print("让我们看看这个特别的元组的真面目吧:{0}".format(new_zoo))
# # print("看看第四个是什么:{0}".format(new_zoo[3]))
# # print("看看第四个中的第二个是什么:{0}".format(new_zoo[3][1]))
#
# zooOne=("a",)
# print("zooOne这个元组的长度为:{0}".format(len(zooOne)))
# print("{0}".format(zooOne[0]))###字典,是以键值对的形式存在,例如:{"张三":"915870915@qq.com","lisi":"123456@qq.com","wangwu":"wangwu@163.com"}# address={"张三":"915870915@qq.com","lisi":"123456@qq.com","wangwu":"wangwu@163.com"}
# print("我是一个字典,我的长度为:{0}".format(len(address)))# ##删除一个元素
# del address["张三"]
# for name,ads in address.items():
#     print("我的键是:{0}".format(name),end='----')
#     print("我的值是:{0}".format(ads))
#
# ##添加一个键值对
# address["六六"]="liuliu@123.com"
# for name,ads in address.items():
#     if(name=="六六"):
#         print("我是新加的成员,我叫{0},我的邮箱是{1}".format(name,ads))
#     else:
#         print("我的键是:{0}".format(name), end='----')
#         print("我的值是:{0}".format(ads))###序列sequence,列表、元组、字符串。在一定意义上就是序列,序列的主要功能是资格检测和索引操作。
##序列都有一种切片运算符,能够对序列中的一个片段,进行操作。(其实就是截取、操作这些序列的某片段)
# tuple=("1","2","3","4")
# list=["a","b","c","d"]
# string='hello'# print("元组的第一个元素是:{0}".format(tuple[0]))
# print("列表的第一个元素是:{0}".format(list[0]))
# print("字符串的第一个元素是:{0}".format(string[0]))
#
# print("元组的第-1个元素是:{0}".format(tuple[-1]))
# print("列表的第-1个元素是:{0}".format(list[-1]))
# print("字符串的第-1个元素是:{0}".format(string[-1]))
#
# print("元组的第2个以后元素是:{0}".format(tuple[1:]))
# print("列表的第2个以后元素是:{0}".format(list[1:]))
# print("字符串的第2个以后元素是:{0}".format(string[1:]))
#
# print("元组的第2个到第三个(不包含第三个)元素是:{0}".format(tuple[1:2]))
# print("列表的第2个到第四个(不包含第四个)元素是:{0}".format(list[1:3]))
# print("字符串的第2个到第五个(不包含第五个)元素是:{0}".format(string[1:4]))
#
# print("元组:  {0}".format(tuple[1:-1]))
# print("列表:  {0}".format(list[:1]))
# print("字符串:{0}".format(string[:-3]))# ###集合set,是无序的。s=set(["a","b","c"])
#
# set=set(["a","b","c"])
# setcopy=set.copy()
# setcopy.add('dd')
# print("set是不是setcopy的子集:{0}".format(set.issubset(setcopy)))
# for i in setcopy:
#     print("我是一个复制的集合,我的元素:{0}".format(i))
#
# setcopy.remove("a")
# print("set和setcopy的交集:{0}".format(set&setcopy))# ###引用,在复制一个对象时,最好使用切片,来复制对象,否则会带来很大的麻烦
# shoplist=["apple","xioami","nuoio"]
# mylist=shoplist;#两者公用的一个对象地址
# del shoplist[0]
#
# print("shoplist=",shoplist)
# print("mylist=",mylist)
#
#
# copylist=shoplist[:]#两者不会公用一个对象地址
# del copylist[0]
# print("shoplist=",shoplist)
# print("copylist=",copylist)# ###有关字符串的更多内容。
# name="xiechanghui"
# if name.startswith('xie'):
#     print("我的姓氏为'xie'")
#
# if "ui" in name:
#     print("我的拼音名字里有‘ui’")
#
# if name.find("ang")!=-1:
#     print("我的名字里找到了‘ang’")
#
# #为序列的各元素之间添加字符
# limiter="__*__"
# list=["a","b","c","d"]
# print(limiter.join(list))


这里给出下一篇链接:Byte-of-python笔记代码3:Object.py

  相关解决方案