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