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