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
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, ....
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'
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'
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