The basic knowledge of the day Python

Source: Internet
Author: User

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:

    1. After you start the program, let the user enter the payroll, and then print the list of items
    2. Allow users to purchase items based on their product number
    3. After the user selects the product, checks whether the balance is enough, enough on the direct debit, enough to remind
    4. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.