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
    >>>

  • 相关阅读:
    BZOJ3566: [SHOI2014]概率充电器
    BZOJ5018: [Snoi2017]英雄联盟
    BZOJ4627: [BeiJing2016]回转寿司
    BZOJ4719: [Noip2016]天天爱跑步
    BZOJ1511: [POI2006]OKR-Periods of Words
    BZOJ4721: [Noip2016]蚯蚓
    BZOJ1922: [Sdoi2010]大陆争霸
    BZOJ2525: [Poi2011]Dynamite
    单选按钮 / 复选框 样式自定义
    HDU 产生冠军 2094
  • 原文地址:https://www.cnblogs.com/cmnz/p/6879609.html
Copyright © 2011-2022 走看看