python function ①

What is a function?

A process that has a function according to the purpose is prepared in advance so that it can be used in the program. Creating a new function is called "defining a function". "Calling a function" means executing a function, and the called function returns a return value as an execution result to the caller. It is also possible to specify the value required for processing at the time of calling as an argument, and specifying the argument is called "passing the argument".

Argument → (input) → function → (output) → return value

What is an index?

An integer that represents the number of a character in a character string. Also called a subscript. Index specification: Character string [index]

ex)>>>s='sunday'    >>>s[0]    's'

The index can also be specified as a negative number. The index corresponding to the last character of the string is -1, and the index decreases toward the beginning of the string as -2, -3, ....

String slice

Strings in python cannot be changed after they are created. This property is called "immutable". There is a way to retrieve the string → it's a slice! !! !! !!

** String [start index: end index] **

ex)>>>a='123456'    >>>a[0:3]     '123'

Can be combined  ex)a[:3]+a[3:] = '123456'

Use steps

Create a new string by extracting characters from the original string

** String [Start index: End index: Step] **

ex) >>> a ='Aiue Okaki Sashisuseso'     >>>a[::5] 'Akasa'

Negative number steps

If you use a negative number for a step, you can create a string that is the reverse of the original string.

ex) >>> a ='Omoikaruishi'    >>>a[5:2:-1] "Is it?" If you use a negative number for a step, the start index will be to the right of the end index.

Recommended Posts

python function ①
[Python] function
python function ②
python enumerate function
Python> function> Closure
[Python] Generator function
Python> function> Inner function
Python function decorator
About function arguments (python)
Function execution time (Python)
Python
Python function argument summary
Python print function (sequel)
Python: About function arguments
Time floor function (Python)
Create a function in Python
Use callback function in Python
[python] Value of function object (?)
ntile (decile) function in python
[Python] Etymology of python function names
About python beginner's memorandum function
About the enumerate function (python)
python url setting include function
Python #function 2 for super beginners
Nonlinear function modeling in Python
Draw implicit function in python
Python higher-order function (decorator) sample
Immediate function in python (lie)
kafka python
[Python] What is a zip function?
Call a Python function from p5.js.
Python basics ⑤
python + lottery 6
Python Summary
Built-in python
Python comprehension
Studying python
[python] Callback function (pass function as argument)
Implement R's power.prop.test function in python
Python 2.7 Countdown
Python memorandum
Python FlowFishMaster
Python service
python tips
Function argument type definition in python
Python basics
Python memo
Included notation in Python function arguments
ufo-> python (3)
Python comprehension
install python
Python Singleton
Python basics ④
Python Memorandum 2
python memo
Python Jinja2
Python increment
atCoder 173 Python
Python installation
Write AWS Lambda function in Python
python tips