Level 1 : What will be the output of the following Python code?


A = [[1, 2, 3],
     [4, 5, 6],
     [7, 8, 9]]
[A[i][i] for i in range(len(A))]

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