[PYTHON] Sum from 1 to 10

>>> sum(range(11))
>>> sum([i for i in range(1,11)])
>>> sum(i for i in range(1,11))
>>> import functools
>>> from functools import reduce
>>> reduce(lambda x,y: x + y, range(1,11))
>>> from operator import add
>>> reduce(add, range(1,11))
>>> def add_r(n):
	if n == 0:
		return 0
	return n + add_r(n-1)

>>> add_r(10)
>>> def add_tr(n, r=0):
	if n == 0:
		return r
	r += n
	return add_tr(n-1, r)

>>> add_tr(10)
>>> s = 0
>>> for i in range(1, 11):
	s += i
>>> s

Recommended Posts

Sum from 1 to 10
Changes from Python 3.0 to Python 3.5
Transition from WSL1 to WSL2
From editing to execution
Post from Python to Slack
Cheating from PHP to Python
Porting from argparse to hydra
Migrating from Chainer v1 to Chainer v2
Anaconda updated from 4.2.0 to 4.3.0 (python3.5 updated to python3.6)
Migrated from Flask-RESTPlus to Flask-RESTX
Update python-social-auth from 0.1.x to 0.2.x
Migrate from requirements.txt to pipenv
Switch from python2.7 to python3.6 (centos7)
Connect to sqlite from python
Call Matlab from Python to optimize
From Elasticsearch installation to data entry
vtkXMLUnstructuredGridReader Summary (updated from time to time)
vtkOpenFOAMReader Summary (Updated from time to time)
How to use SWIG from waf
Engineer vocabulary (updated from time to time)
Create folders from '01' to '12' with python
Conversion from pdf to txt 1 [pdfminer]
Post from python to facebook timeline
[Lambda] [Python] Post to Twitter from Lambda!
Convert from pdf to txt 2 [pyocr]
Connect to utf8mb4 database from python
OpenMPI installation from download to pass-through
Tensorflow memo [updated from time to time]
Python (from first time to execution)
Post images from Python to Tumblr
Send commands from Atom to Maya
How to launch Explorer from WSL
Programming to learn from books May 7
From Ubuntu 20.04 introduction to environment construction
Ssh connect to GCP from Windows
How to access wikipedia from python
Python to switch from another language
How to convert from .mgz to .nii.gz
Migrate from VS Code to PyCharm
pynq-z1 From purchase to operation check
Review from git init to git push
Did not change from Python 2 to 3
Update Python on Mac from 2 to 3
Change AWS EC2 instance from t2 to t3
Connect to Packetix VPN from CentOS 7 minimal.
[Python] Fluid simulation: From linear to non-linear
How to create a clone from Github
Let Code Day75 starting from scratch "15.3 Sum"
SIGNATE Quest ① From data reading to preprocessing
Connect to Docker's MySQL container from Flask
Why I moved from Java to Dart
From Python to using MeCab (and CaboCha)
Reinforcement learning to learn from zero to deep
How to easily convert format from Markdown
[Linux] Flow from power-on to PC startup
[Note] [PyTorch] From installation to easy usage
Script to generate directory from json file
Execute a script from Jupyter to process
How to update Google Sheets from Python
Convert from PDF to CSV with pdfplumber
[TF] How to use Tensorboard from Keras