** 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