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