・ Count specific characters
python
>>> string = "aaAAAaAAa"
>>> string.count("a")
4
・ Count the number of elements in the list
python
>>> line = ["a", "b", "c", "d"]
>>> print(len(line))
4
・ Number of digits
python
>>> num = 1000
>>> print(len(str(num)))
4
・ Make a list of character strings character by character
python
>>> string = "AtCoder"
>>> print(list(string))
['A', 't', 'C', 'o', 'd', 'e', 'r']
-Standard input (multiple inputs on multiple lines)
python
N
s_1
s_2
s_3
...
s_N
>>> N = int(input())
>>> s = [input() for i in range(N)]
>>> print(s)
['s_1', 's_2', 's_3',...,'s_N']
·Absolute value
python
>>> x = -5
>>> y = abs(x)
>>> print(y)
5
-Convert from string list to numeric list
python
>>> list_a = ['1', '2', '3']
>>> num = [int(s) for s in list_a]
>>> print(num)
[1, 2, 3]
Recommended Posts