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