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