[Python] Memo about functions

** split function ** Separate and list character strings containing numbers, alphabets, symbols, etc.

test = orange,apple,banana,strawberry
URL  = https://aaaa/bbbb/cccc/dddd

#The list "test",Separated by
#* Maybe you specify the symbol you are using.
test.split(",") 
['orange', 'apple', 'banana', 'strawberry']

URL.split("/")
['https:', 'aaaa', 'bbbb', 'cccc', 'dddd']


#If nothing is specified in the argument, it will be automatically separated by spaces or tabs.
test.split()
['orange', 'apple', 'banana', 'strawberry']

** input function ** Function for receiving standard input (prepared data)

#In the case of one shot
aaa = input()

#For multiple lines
#* In the case of input data with line breaks, if it remains as follows\Be careful as n will be included
import sys
a = sys.stdin.readlines():

** randrange function ** Randomly select elements from the elements of range () (in the list below)

import random
line = input().rstrip()
list = line.split(",")
# ["A", "B", "C"]

num = len(list)

# randrange(start, stop, step)It seems to be described as, but start,step can be omitted
print(list[random.randrange(num)])

** translate, maketrans function ** Specify multiple characters to replace

t = str.translate(str.maketrans("ABCDEF", "123456"))
* If the replacement target is specified as None, the replacement source will be deleted.

I will update what I have learned from time to time.

Recommended Posts

[Python] Memo about functions
[Python] Memo about errors
Python memo
python memo
Python memo
Python functions
python memo
Python memo
Python memo
Python memo
Python control syntax, functions (Python learning memo ②)
About python dict and sorted functions
About python slices
[Python] Memo dictionary
About python comprehension
About Python tqdm.
About python, class
python beginner memo (9.1)
About Go functions
About python inheritance
★ Memo ★ Python Iroha
About python, range ()
[Python] EDA memo
Python 3 operator memo
About python decorators
#Python basics (functions)
[Beginner] Python functions
[My memo] python
Python3 metaclass memo
[Python] Basemap memo
About python reference
About Python decorators
Python Easy-to-use functions
[Python] About multi-process
Python basics: functions
Python beginner memo (2)
[Python] Numpy memo
Memo of troubles about coexistence of Python 2/3 system
About Python for loops
Python Beginner's Guide (Functions)
Summary about Python scraping
Python basic course (12 functions)
Python class (Python learning memo ⑦)
About function arguments (python)
My python environment memo
python openCV installation (memo)
Python module (Python learning memo ④)
A Java programmer studied Python. (About functions (methods))
Visualization memo by Python
Python test package memo
Summary about Python3 + OpenCV3
About Python, for ~ (range)
A memo about writing merge sort in Python
python regular expression memo
Binary search (python2.7) memo
[My memo] python -v / python -V
About Python3 character code
Python3 List / dictionary memo
[Memo] Python3 list sort
Python Tips (my memo)
About Python development environment