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