美文网首页
Python学习(一)

Python学习(一)

作者: 午后凉白开 | 来源:发表于2018-12-15 00:12 被阅读0次

    列表

    定义

    a = [1,2,3,4,5,6]
    type(a)
    a[0]
    a[4] = 99
    
    

    切片

    
    a[0:2]
    a[1:]
    a[:-1]
    
    

    字典

    me = {'height':180}
    me['height']
    

    布尔型

    True、False

    循环语句

    for i in [1,2,3]:
        print(i)
    

    构造函数只在生成类的实例时被调用一次。方法中为什么要加入self,目的是可以调用实例变量。

    
    class 类名:
        def __init__(self,参数,...) #构造函数
            ...
        def 方法名1(self,参数,....)
            ...
    

    Matplotlib

    绘制简单图形

    
    import numpy as np
    import matplotlib.pyplot as plt
    
    x = np.arange(0,6,0.1)
    y = np.sin(x)
    plt.plot(x,y)
    plt.show()
    
    

    相关文章

      网友评论

          本文标题:Python学习(一)

          本文链接:https://www.haomeiwen.com/subject/xdtohqtx.html