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