'{0}, {1}, {2}...'.format(Variable 1,Variable 2,Variable 3 ....) #Specified by index (subscript)
The f string (f-strings) puts f or F before the string literal (f'xxx', F'xxx'). Variables can be specified as they are in the replacement field in the string.
print(f'{a} and {b}')
# 123 and abc
print('from %s to %s'(year1, year2))
In the case of execution from the command line, execution stops here and you are prompted to enter a number. If a non-numeric value is entered, the program will end there.
try:
kai = int(input('How many times?Enter in half-width numbers:'))
except ValueError:
print('Not a valid number.')
quit()
if kai == 1:
hoge
elif kai == 2:
fuga
You can also put an argument after the file name when executing from the command line.
python hoge.py hoge1 hoge2
When you execute
import sys
args = sys.argv
print(args)
#[hoge.py, hoge1, hoge2]
#First get the file name
fname = os.path.basename(__file__)
#Cut out the relevant part from the file name
yyyy = fname[0:4]
mm = fname[4:6]
dd = fname[6:8]
Recommended Posts