DAY1
Learning content:
Today is the first day of the course, the first day, understand the history of Python, development prospects, but also drank a large bowl of Alex Teacher's soup. Chicken soup is fresh, then learn or learn.
Today wrote the first Python program, Hello World. Suddenly think of college when learning C language, writing is this. At this moment, add what you want to do, hello Python,i ' m coming.
Note: Uppercase represents constants, such as Pie;
The origins of ASCII, as well as gb2312, GBK, gb18031, and utf-8 are encoded by birth;
Note: Single line with #, multi-line with "";
Fixed to multi-line variable with "'";
Python default all input is a string;
The Getpass module allows the user to enter a password that is not visible.
DAY2
Learning content:
Guess_answer = 56count = 0while count<3:guess = Int (input ("What ' My Age,please gusess:")) if guess = = Guess_answe R:print (' Got it ') break elif guess > Guess_answer:print (' Thinking less!! ') Else:print (' Thinking lager!! ') Count +=1else:print (' You guess too many ') for I in Range (3): guess = Int (input ("What ' My Age,please gusess:")) if Guess = = Guess_answer:print (' You Got it ') break elif guess > Guess_answer:print (' Thinking L ess!! ') Else:print (' Thinking lager!! ') Else:print (' You guess too many ') while count <3:guess = Int (input ("What ' My Age,please gusess:")) if guess = = Guess_answer:print (' Got it ') break elif guess > Guess_answer:print (' Thinking less!! ') Else:print (' Thinking lager!! ') Count +=1 if count = = 3:continue_guess = input (' Do you want guessing again? ') If continue_guess! = ' n ': Count= 0
The above small program is used to guess the answer, the first time to write a small program, feeling a great harvest. Today's assignment is the landing program and the level three menu, all smoothly completed.
Notes:
Continue: Jump out of this cycle, into the next cycle;
Break: Interrupts the entire cycle;
Pass: Skip
OS module:
Os.system ("dir") executes the command without saving the result
Os.popen ("dir"). Read () The previous execute command with the stored result, followed by Read () reading the result
Os.mkdir ("file name") to create a directory
The smallest unit that can represent (store) in a computer, is a binary (bit)
8bit = byte (bytes)
1024byte = 1kbyte
& 13 results are (and)
60 | 13 result is a (or)
Ternary operations:
A,b,c = 1,3,5
D = A If a < b else C if condition is established, d = A, otherwise d = C
Encode encoding
Decode decoding
String <-----> bytes
DAY3
Learning content:
Today I studied lists, Ganso and dictionaries.
names = ["Dzk", "PXM", "Zd", "ZM"]print (Names[0]) names.append (all) print (names) print (Names[1:2]) print (names[-3:-1])
Above is some usage of the dictionary. Also wrote the shopping cart homework:
Import Yaml #导入yaml模块f = open (' Shoping_list ', "RB") Goods_dict = Yaml.load (f) #利用yaml模块将信 To the Product list print (goods_dict) Dict_user = {} #定义老用户名单字典file =open ("User", "R", encoding= "Utf-8") for line I n file:key,vaule = Line.strip (). Split (":") dict_user[key] = Vaule #将老用户文件内容转成字典file. Close () Buy_list = [] #定义已购商品列表dict_olduser_info = {} #定义老用户已购买信息print ("Wlecome to shoping m All ") #输出欢迎信息username = input (" Please input your name>>> ") Password = input (" Please input your PASSW Ord>>> ") def exit_shoping (): #定义程序退出函数 print ("--------you have bought \033[32 1m%s\033[0m-------"% buy_list) exit () def shoping (user_wage): #定义用户购买商品程序函数, convenient is the call of the old user While True:print (goods_dict) Number = input ("chose the number (Q to exit):") if NUMBER.ISDI Git (): #判断用户输入的商品编号是否是数字 buy_number = Int (number) if Buy_number in Goods_dict: #判断用户输入的商品编号是否存在 if User_wage >= goods_dict[buy_number][1]: #用户的工资够买商品 user_w Age-= goods_dict[buy_number][1] Buy_list.append (goods_dict[buy_number][0]) print ("Y OU chose \033[32;1m%s \033[0m,you left \033[32;1m%s \033[0m "% (goods_dict[buy_number][0],user_wage)) Else : Print ("You haven ' t enough money") #用户工资不够买 exit_shoping () Else: Print ("The Goods List don ' t has this number") elif number = = ' Q ': With open ("Buy_info", " A + ", encoding=" Utf-8 ") as File2: #用户退出时, save the user balance to a file for the next call to File2.write (" \ n "+username+": "+str (User_wage)) With open ("User", "A +", encoding= "Utf-8") as File1: #用户退出时, the user name is stored in the file for the next call to File1.write ("\ n "+username+": "+ Password ) exit_shoping () else:print ("Wrong number,please input again") if username not in Dict_user: #检验用户是新用户 user_wage = Int (input ("your wage:")) shoping (user_wage) elif use Rname in Dict_user: #用户是老用户 with open ("Buy_info", "r+", encoding= "Utf-8") as File3: For line in File3:key, Vaule = Line.strip (). Split (":") dict_olduser_info[key] = Vaule Left_wa GE = int (dict_olduser_info[username]) print ("You had \033[32;1m%s \033[0m money"% (Dict_olduser_info[username])) SH Oping (Left_wage)
Notes
List
1. Slicing
2. Insert: Insert (1, "") 1 for insertion position
3. Delete a >> names.remove ("")
b >> del name [] #删除指定位置
C >> Names.pop ("") #可指定下标, otherwise the last one is deleted by default
4. Find Names.index ("")
5, Statistics number Names.count ("")
6. Reverse Names.reverse ("")
7. Merging Names.extend (name2)
8, Shallow copy names.copy () = Name2
9. Deep Copy Import copy
name2 = copy.deepcopy (names)
Ganso (non-modification, deletion, addition)
1. Index #索引
2. Count #统计个数
Dictionary (Key-value)
1, the dictionary is unordered, there is no subscript
2. Delete del info["key"]
info.pop["Key"]
Info.popitem () #随机删
3, SetDefault ("Key", "value") #创建一个新值
4. Items () #把字典转换成列表
python-first piece, notes Finishing and Learning Content review (DAY1-DAY2-DAY3)