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