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