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