l = [1,2,3,3,3,44,4,4,1] print(set(l)) s = set() s = {1,2,3,4} def my(name,sex=‘男‘): #形式参数 print(‘hahaha‘,name) return name my(‘111‘)#实际参数 def read_file(file_name): with open(file_name,encoding=‘utf-8‘) as f: return f.read() import datetime def welcome(name): msg = ‘欢迎登录【%s】,今天的日期是 【%s】‘%(name,datetime.date.today()) print(msg) import json f = open(‘a.txt‘,‘w‘,encoding=‘utf-8‘) # res = f.read() # json.loads(res) # # json.load(f) #把json串变成字典 goods = { ‘宝马‘:11111, ‘奔驰‘:22222 } print(json.dumps(goods)) # json.dumps(d) #把字典转成json # json.dump(goods,f,ensure_ascii=False)# json会帮你write一次 msg = ‘欢迎光临 {name} ,今天的日期是 {today} ‘ msg = msg.format(name=‘刘欣雨‘,today=datetime.datetime.today() ) print(msg) # sql = ‘insert into my_user value ({id},{name},{addr},{sex},{phone}) ‘ # sql.format(name=‘aaa‘,addr=‘sdfsfd‘,sex=‘xxx‘,id=11) # sql = ‘insert into {} value {}; ‘.format(‘abc,‘,‘bcd‘) # print(sql) # sql=‘insert into my_user value (%s,%s,%s,%s,%s,%s,%s,%s)‘%(id,name,sex,addr,phone,) # + # %s # format_map d = {‘name‘:‘小黑‘,‘sex‘:‘不知道‘} words =‘名字 {name} ,性别 : {sex}‘.format_map(d) print(words) #字符集 # 只认识2进制 0 1 # 0 1 # 阿斯克码表 12 {}
原文地址:https://www.cnblogs.com/Noul/p/9278712.html
时间: 2024-10-28 16:05:39