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