Re-learning Python-day 04-python Foundation---tuple + dictionary + string

Source: Internet
Author: User

Meta-group

Tuple: The feature is the content is not variable, the list of read-only, can be queried, cannot be modified

A = 2,print(a)print= ('a','b  ','C')print(b[1])

Operation Result:

(2,)<class'tuple'>b

Dictionary

Dictionary: Internal data is out of order when printed, the key value is hash, and there is uniqueness

#Create a dictionaryA = {'a':'python','b':'Ruby','C':'Java'}#Create a dictionary directlyPrint(a)#built-in Dictionary method creation: DictA = Dict (('a','b'),))Print(a) a= Dict ([['a','b'],])Print(a)#Modify DictionaryA = {'a':'b'}set1= A.setdefault ("C","Java")Print(a)Print(Set1)#Query OperationsA = {'a':'python','b':'Ruby','C':'Java'}Print(A.keys ())Print(A.values ())Print(A.items ())Print(a['a'])#Update MethodA = {'a':'python','b':'Ruby','C':'Java'}b= {'D':'Shell'}a.update (b)Print(a) a.update ({'a':'JavaScript'})Print(a)#Delete MethodA = {'a':'python','b':'Ruby','C':'Java'}a.clear ()Print(a)#Empty Dictionarya= {'a':'python','b':'Ruby','C':'Java'}dela['a']Print(a)Print("********************") A= {'a':'python','b':'Ruby','C':'Java'}b= A.pop ('b')Print(a)Print(b)Print("********************") A= {'a':'python','b':'Ruby','C':'Java'}b=A.popitem ()Print(a)Print(b) a= {'a':'python','b':'Ruby','C':'Java'}delA#the entire dictionary is deletedPrint('Other Dictionary methods') A= {' First':'python'}b= Dict.fromkeys (['a','b'],['Test'])Print(a)Print(b)Print('the traversal of a dictionary') A= {'a':'python','b':'Ruby','C':'Java'} forI,jinchA.items ():Print(I,J) forIinchA:#efficiency is higher than above    Print(I,a[i])

String

List only a few simple applications

Print('Join String Merge method') A= ['python','Ruby','Java']b="'. Join (a)Print(b) C='*'. Join (a)Print(c)Print('String Common methods') A='python py'Print(A.count ('P'))Print(A.capitalize ())Print("Format formatted output") A="my favorite book {name} and {name2}"Print(A.format_map ({'name':'python','name2':'Java'}))Print(A.format (name ='Shell', name2 ='Bash'))Print(A.isdigit ())

Ps:

The previous data type is only the foundation, mastered the commonly used several built-in functions, the basic grammar can, in the learning function, the object some high-level topic, can continue to consolidate, so continue refueling bar

At work today when looking at Python, is the development of C + + despised, said too simple, alas, continue to refuel it

Re-learning Python-day 04-python Foundation---tuple + dictionary + string

Related Article

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.