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