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