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