zoukankan      html  css  js  c++  java
  • python reverse 和reversed

    没有完全明白,至少试出来了

    >>> a=['I','like','python']
    >>> help(reverse)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'reverse' is not defined
    >>> a.reverse()
    >>> a
    ['python', 'like', 'I']
    >>> help(reversed)

    >>> a=['I','like','python']
    >>> id(a)
    139942318019288
    >>> a.reverse()
    >>> id(a)
    139942318019288
    >>> a
    ['python', 'like', 'I']
    >>> a.reversed()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: 'list' object has no attribute 'reversed'
    >>> help(reversed)

    >>> a.__getattribute_('b')_
      File "<stdin>", line 1
        a.__getattribute_('b')_
                              ^
    SyntaxError: invalid syntax
    >>> a.__getattribute__('b')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: 'list' object has no attribute 'b'
    >>> a.__getattribute__('I')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: 'list' object has no attribute 'I'
    >>> a
    ['python', 'like', 'I']
    >>> a=I like python
      File "<stdin>", line 1
        a=I like python
               ^
    SyntaxError: invalid syntax
    >>> a
    ['python', 'like', 'I']
    >>> reversed(a)
    <listreverseiterator object at 0x7f46ddd20350>
    >>> print list(reversed(a))
    ['I', 'like', 'python']


    >>> a='I like python'
    >>> type(a)
    <type 'str'>
    >>> reversed(a)
    <reversed object at 0x7f46ddd20350>
    >>> print reversed(a)
    <reversed object at 0x7f46ddd71550>
    >>> print list(reversed(a))
    ['n', 'o', 'h', 't', 'y', 'p', ' ', 'e', 'k', 'i', 'l', ' ', 'I']
    >>> a
    'I like python'
    >>> print str(reversed(a))
    <reversed object at 0x7f46ddd20350>



  • 相关阅读:
    drf中 连表深度查询和ListSerializer类包括drf中Response二次封装
    drf中表之间断关联操作
    drf中的序列化家族
    rest_framework框架的封装特点和APIView请求生命周期
    vue项目和django项目交互补充,drf介绍,restful规范
    Vue成绩单
    面向对象编程day2
    面向对象编程day3
    面向对象编程day1
    day13
  • 原文地址:https://www.cnblogs.com/hsdchenliyang/p/9291621.html
Copyright © 2011-2022 走看看