zoukankan      html  css  js  c++  java
  • python_code list_2

    >>> import math
    >>> math.sin(0.5)
    0.479425538604203
    >>>
    >>> import random
    >>> x=random.random()
    >>> n=random.randint(1,100)
    >>> import numpy as np
    >>> a = np.array((1,2,3,4))
    >>> print(a)
    [1 2 3 4]
    >>> from math import sin
    >>> sin(3)
    0.1411200080598672
    >>> from math import sin as f
    >>> f(3)
    0.1411200080598672
    >>> from math import *
    >>> sin(3)
    0.1411200080598672
    >>> gcd(36,18)
    18
    >>> def main():
    if __name__ == '__main__':
    print('This program is run directly.')
    elif __name__ == 'hello':
    print('This program is used as a module.')


    >>> import hello
    Traceback (most recent call last):
    File "<pyshell#72>", line 1, in <module>
    import hello
    ImportError: No module named 'hello'
    >>> alist = ['a','b','mpilgrim','z','example']
    >>> a_list = []
    >>> a_listt = list((3,4,7,9))
    >>> a_listt
    [3, 4, 7, 9]
    >>> list(range(1,10,2))
    [1, 3, 5, 7, 9]
    >>> list('hello world')
    ['h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd']
    >>> list({3,7,5})
    [3, 5, 7]
    >>> list({'a':3,'b':4,'c':5})
    ['b', 'a', 'c']
    >>> list({'a':3,'b':4,'c':5}.items())
    [('b', 4), ('a', 3), ('c', 5)]
    >>> x = list(range(10))
    >>> x
    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    >>> x[0]
    0
    >>> x[1]
    1
    >>> x[-1]
    9
    >>> x[-2]
    8
    >>> x = [1,2,3,4,5,6]
    >>> del x[0]
    >>> x
    [2, 3, 4, 5, 6]
    >>> del x
    >>> x
    Traceback (most recent call last):
    File "<pyshell#92>", line 1, in <module>
    x
    NameError: name 'x' is not defined
    >>> x = {'a':3,'b':4,'c':5}
    >>> del x['b']
    >>> x
    {'a': 3, 'c': 5}
    >>> x1 = x['c']
    >>> x1
    5
    >>>

  • 相关阅读:
    javascript 犀牛书
    Hmtl/css
    SQL Server 查询中使用Union或Union All后Order by排序无效(嵌套查询乱序)
    CSS 动画
    CSS 文字排版
    CSS 太极图
    Amazon Products 服务费估算
    CSS3 结构伪类选择器
    JS 执行机制
    vue 生命周期函数的学习
  • 原文地址:https://www.cnblogs.com/cmnz/p/6879609.html
Copyright © 2011-2022 走看看