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