Basic Python command memo

・ 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

Basic Python command memo
Python basic memo --Part 2
Python basic grammar memo
Python basic memo --Part 1
Python memo
Python memo
Python Basic Grammar Memo (Part 1)
virtualenv Basic command usage memo
Python basic grammar (miscellaneous) Memo (3)
python memo
command memo
Python memo
Command memo
Python basic grammar (miscellaneous) Memo (4)
Python memo
Python memo
Linux command (basic in basic) personal memo
[Python] Memo dictionary
RF Python Basic_01
python beginner memo (9.2-10)
Linux command <Basic 2>
python beginner memo (9.1)
scp command memo
who command memo
Flask basic memo
Linux # Command Memo 1
Basic Python writing
★ Memo ★ Python Iroha
[Basic] linux command
[Python] EDA memo
Python 3 operator memo
Python3 basic grammar
Linux command <Basic 1>
[My memo] python
Python3 metaclass memo
RF Python Basic_02
[Python] Basemap memo
Python beginner memo (2)
[Python] Numpy memo
Python basic course (12 functions)
Python class (Python learning memo ⑦)
Python basic grammar / algorithm
My python environment memo
Python Basic Course (7 Dictionary)
python openCV installation (memo)
Python module (Python learning memo ④)
Python basic course (2 Python installation)
vi (vim) command memo
Basic sorting in Python
Visualization memo by Python
Numpy basic calculation memo
Python basic course (9 iterations)
[python] class basic methods
Python test package memo
Python Basic Course (11 exceptions)
[Python] Memo about functions
Linux basic command memorandum
Execute command from Python
Python basic course (6 sets)
Python3 cheat sheet (basic)
python regular expression memo