-
f'{}'
Python3.6及以上版本才有,Python3.5及以下版本会出错。 -
'%s'%()
常用格式 -
'{}'.format()
{}
里面可以带数字也可以不带数字,带数字编号可以调换输出顺序,还可以带关键字。device = torch.device(f'cuda:{opt.local_rank}') #python3.6 device = torch.device('cuda:%s' % (opt.local_rank)) #python3.5 device = torch.device('cuda:{0}'.format(opt.local_rank))
-
demo
# `f'{}'` mode key = f"{size}-{str(i).zfill(5)}".encode("utf-8") # `'{}'.format()` mode key = "{0}-{1}".format(size, str(i).zfill(5)).encode("utf-8")
# `f'{}'` mode print(f"Make dataset of image sizes:", ", ".join(str(s) for s in sizes)) # `'{}'.format()` mode print("Make dataset of image sizes:", ", ".join(str(s) for s in sizes))
# `f'{}'` mode mask_path_base = f"data/{dataset_name}/local_editing" # `'{}'.format()` mode mask_path_base = "data/{0}/local_editing".format(dataset_name)
# `f'{}'` mode f"{args.save_image_dir}/source_reconstruction/{index_src}_{index_ref}.png" # `'{}'.format()` mode "{0}/source_reconstruction/{1}_{2}.png".format(args.save_image_dir, index_src, index_ref)
参考资料
python:f/F,format,%的用法
python的格式化语句的三种写法 %s , f “”, format