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