Level 10 : What will be the output of the following Python code?


>>> a=(0,1,2,3,4)
>>> b=slice(0,2)
>>> a[b]

Author: SarojiniD | Tags: slice | 1859+ Python FAQs | Share
__all__-attribute | sets | iterable | attribute | integer | built-in-modules | function-and-scope | benefit | identifier | classes | comparison | gil | directory-operations | __init_subclass__ | keyword | library | exponentiation | bitwise-operator | file-handling | call | encoding | dictionary | collection | frozenset | error-handling | class-decorators | data_structure | import-method | input | arithmetic-expression | complex | using-yield-in-functions | function | init | class | statement | conversion | functional-programming | data-structure | string-iteration | booleans | single-inheritance | aggregating-data-with-functools.reduce() | sum() | string-concatenation | sorting-and-ranking | inheritance | reading:-read(),-readline(),-readlines() | conditional-statement | command-line-parsing | recursion | syntax-error | with-statement | list-comprehensions | working-with-file-paths | overriding-methods | string-slicing | string-formatting | class-and-inheritance | touples | formal-and-actual-parameter | python_version | logical-operator | update | min-max-function | name-mangling | python-django | list-methods-and-slicing | file | numpy | decorator | yield | working-with-dates-and-times | min-function | python-module | boolean | using-lists-as-stacks | advanced-file-operations | lambdas | async | control-flow | python-repl | built-in-function | pseudocode | sys-module | loops | application | shallow-copy | parsing-with-strptime | type-conversion-and-casting | using-else-and-finally | return-statement | key-value-pairs | variable | dictionary-methods | filter-function | zfill-function | math-copysign | virtual-environment | turtle | quantifiers-(*,-+,-?,-{}) | virtual-environment | list | pass | context-manager | condition | creating-and-starting-threads | datatype | method | tuple-methods | class-and-object | data-type-conversions | handling-missing-values-(fillna,-dropna) | exception-handling | time-series-with-pandas | syntax-error | odd-number | membership-operators-(in,-not-in) | filter | identity-operators-(is,-is-not) | zip | multiple-inheritance | complex-number | creating-custom-modules | append | string-method | string-slicing | deep-copy | threading | descriptors | goto-function | thread-synchronization | operator-or | default-arguments | difference-between-threads-and-processes | arbitrary-arguments-(*args,-**kwargs) | magic-method | sys | factorial-function | data-structures | lambda-function | def | walking-through-directories-using-os.walk() | opening-files-(open()) | method-overloading | list-comprehension | constructor | dataframe-and-series-objects | writing:-write(),-writelines() | memory-management | test-discovery | else-statement | file_handling | dictionaries | data-type | print-statement | polymorphism | comprehension | built-in-function | binary | generators | list-method | choice | list-slicing | introduction-to-threads | indentation | mathematical-function | input-function | memory | built-in | global-keyword | asyncio-module | string-method | format | oop | expression | escape-operator | arithmetic-operation | assignment-operators | loop-control-statements | class-and-instance-variable | string-formatting | staticmethod | object-attribute | namespace | lists | joining-and-merging-dataframes | slicing | bitwise-operator | array | mysql | mathematics | filtering-and-indexing | bitwise | raise-statement | managing-directories-with-os-and-shutil | head-and-tail | assignment-operator | sum-function | range | generator | center | basic | mutable | anchors-(^,-$) | feature | binary-operation | namedtuple | operators | operator-overloading | comment | version-check | methods | regex | string-methods | random-function | immutability | literal-characters-and-special-characters | asyncio | static-method | why-use-multiprocessing-over-threading?-(gil) | precedence | boolean-masking | typeerror | sorting | matrix-list-comprehension | list-mutation | nested-loop | id-function | using-map()-for-transformations | python-syntax-and-structure | objects | function-argument | access-modifier | regular-expression | boolean-and-non-boolean | input-function | data-types | default-mutable-argument | operations | __future__ | regular-expressions | set-operation | multiple-except-blocks | matrix | implementation | python-operators | assert | collections | operator-and | datetime.date,-datetime.time,-datetime.datetime | using-the-threading-module | python-history | debugging | thread | expand-tab | loop-control | conditional-statements | defining-functions | destructor | pickling--unpickling | tuple | enumerate() | thread-safe-data-structures-(queue.queue) | slice | fabs-function | reading-and-writing-files | else | numeric | decimal | identity-operator | encapsulation | conditional-statement | raise | counter-function | operator | exception | logical-operators | interpreter | stack | global-variable | compute | intering | reading-and-writing-large-files-efficiently | exception-handling | iterators | working-with-binary-files-(rb,-wb) | introduction-to-python | rollback | datetime | global-variable | sorted | dictionary-comprehensions | pep | error-handling | working-with-temporary-files-using-tempfile | unit-testing | floating-point-precision | split | using-join()-and-is_alive()-methods | for | data-type | introduction-to-multiprocessing | map-function | list-indexing | lambda | control-flow | operand | overflow | join | control-statement | design-principle | counter | copy | generators-in-python | using-os-and-pathlib-modules | scientific-notation | postfix | package-management | integers | round-function | data-structure | python | list-operation | heap-memory | random | type-conversion | module | precedence-and-associativity | set | string | floats | parameter | formatting-with-strftime | error | data-structures-in-python | string-manipulation | functions | iterator | file-handling | immutable-data-type | installation | max-min | pandas | inherit | swapping | oops | syntaxerror | loop | docstring | software-design | print | while-loops | multiple-inheritance | while-loop | list-comprehension | global | while-and-for-loop | math | lambda-functions | invalid-list | zip-function | logical-operation | indexing | list,-set,-and-dictionary-comprehensions | round | int | list-vs-tuple | indexing:-loc-vs-iloc | matplotlib | mapping-function | using-assertions-(assertequal,-assertraises) | logical-operator | multithreading | match | higher-order-function | type_conversion | list-join | multiprocessing | tuples | strings | while-else-loop | tuple-unpacking | syntax | type-conversion | version | recurssion | identity-operator | functional-programming | dicts ...