1. Call function-----in the same directory, call the user name password login module
2. Create a folder
Create a folder #os Os.mkdir ("NEW_DD3")
Ternary
3. Convert to binary encode
msg="new_msg=msg.encode (' utf-8 ') print (new_msg)
Converting binary into other (decode)
msg=" my Hometown"
New_msg=msg.encode ('utf-8 ') gb_msg=new_msg.decode (' utf-8 ') print (gb_msg)
Binary conversion to other decode
msg=" I love Beijing"print (Msg.encode (encoding=' Utf-8 '). Decode (' utf-8 ' ) Convert to other
4. List
Name =["Zhangsan" "Lisi" , " Wangwu " prin T (Name.index ( " Zhangsan " # subscript display
!--? XM L:namespace prefix = "o" ns = "Urn:schemas-microsoft-com:office:office"/--> /span>
ListName =["Zhangsan","Lisi","Wangwu","Lisi"]Print(Name.index ("Zhangsan"))# Subscript DisplayPrint(Name.append ("Likui"))#AddPrint(name) Name.insert (1,' Wangerxiao ')# in the subscript that inserts, that is to specify the insertion placePrint(name)Print(Name.count ("Lisi") name2=[ " Mao " Span style= "color:teal; FONT-SIZE:15PT, "lang=" en-us ">" Gou " " tu " " Name.extend (name2) # Name and name2 merge print (name)
!--? xml:namespace prefix = "o" ns = "Urn:schemas-microsoft-com:office:office"/-->
span>
5.copy latent copy, first layer unchanged, second layer change ()
name=[' A ',' B ',' C ', [' d ',' F '#-1name[2]=300 Print ( Name) print (name2)
6. Take one from one
name=[' Alex ',' Zhang ',' Wang ',' Li ',' Zhao ',' Han ',' Chu '] print(name[0:-1:2])#0 from the beginning,-1 for the last, 2 for onefor each, That is, from beginning to end, take one (take the head not to take the tail )
7. Program: Shopping Cart Program
Demand:
- After you start the program, let the user enter the payroll, and then print the list of items
- Allow users to purchase items based on their product number
- After the user selects the product, checks whether the balance is enough, enough on the direct debit, enough to remind
- You can exit at any time to print the purchased goods and balances when exiting
#-*-Coding:utf8-*-shopping_list=[]product_list=[('Ipone', 3800), ('MAC', 1200), ('Bike', 600),]salary=input ("Enter Salary:")ifSalary.isdigit ():#whether a string contains only numbersSalary=int (Salary)#Convert to Plastic whileTrue: forIndex, iteminchEnumerate (product_list):#get subscript as product number Print(Index, item) User_choice=input ("user Input Product code:") ifuser_choice.isdigit (): User_choice=Int (user_choice)ifUser_choice<len (Product_list) anduser_choice>=0:p_item=Product_list[user_choice]ifp_item[1]<=Salary:shopping_list.append (p_item) Salary-=p_item[1] Print("Item {INFO1}, balance \033[31;1m{info2}\033[0m". Format (info1=product_list,info2=salary)) Else : Print("Insufficient Balance") Else: Print("product does not exist") Else: Print("Press any key to exit") Else: Print("Wage input Error")
The basic knowledge of the day Python