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