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