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