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