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