Level 1 : What will be the output of the following Python code?


a=[1,2,3,4]
b=[sum(a[0:x+1]) for x in range(0,len(a))]
print(b)

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