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