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