• 技术文章 >Python技术 >Python基础教程

    如何使用python中的add函数?

    宋雪维宋雪维2021-02-03 18:16:18原创17223

    image.png

    本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

    add函数使用方法

    1、numpy中加法运算

    使用实例

    import numpy as np
     
    arr1 = np.array([[4, 7], [2, 6]], 
                     dtype = np.float64)
    
    arr2 = np.array([[3, 6], [2, 8]], 
                     dtype = np.float64) 
     
    # Addition of two Arrays
    Sum = np.add(arr1, arr2)
    print("Addition of Two Arrays: ")
    print(Sum)

    2、set中添加元素

    add()方法用于给集合中添加元素,如果要添加的元素在集合中已经存在,则不添加。

    使用实例

    fruits = {"a", "b", "c"} 
    fruits.add("d") 
    print(fruits)

    输出

    {'a', 'b', 'c', 'd'}

    以上就是python中add函数的两种用法,希望能对有所帮助哦~

    专题推荐:pythonadd函数
    品易云
    上一篇:python中global是什么意思? 下一篇:python中upper函数的用法是什么?

    相关文章推荐

    • python repr()与str()区别总结• python中实现字符与ascll码相互转换方法• 如何使用python中iter函数?• python中global是什么意思?

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网