Re-learn Python, learn python

Source: Internet
Author: User

Re-learn Python, learn python
Tuples

 

Tuples: The feature is that the content is not changeable and the read-only list can be queried and cannot be modified.

a = 2,print(a)print(type(a))b = ('a','b','c')print(b[1])

Running result:

(2,)<class 'tuple'>b

 

Dictionary

 

Dictionary: Internal data is unordered during printing, and key values are hashed and unique.

# Create a dictionary a = {'A': 'python', 'B': 'Ruby ', 'C': 'java'} # directly create a dictionary print () # built-in dictionary method creation: dicta = dict ('A', 'B'),) print (a) a = dict ([['A ', 'B'],]) print (a) # modify Dictionary a = {'A': 'B'} set1 =. setdefault ("c", "java") print (a) print (set1) # query operation a = {'A': 'python', 'B': 'ruby ', 'C': 'java'} print (. keys () print (. values () print (. items () print (a ['a']) # update method a = {'A': 'python', 'B': 'ruby', 'C ': 'java'} B = {'D': 'shell'}. update (B) print (a). update ({'A': 'javascript '}) print (a) # Delete method a = {'A': 'python',' B ': 'ruby ', 'C': 'java'}. clear () print (a) # clear the dictionary a = {'A': 'python', 'B': 'Ruby ', 'C ': 'java'} del a ['a'] print (a) print ("********************") a = {'A': 'python', 'B': 'ruby', 'C': 'java'} B =. pop ('B') print (a) print (B) print ("********************") a = {'A': 'python', 'B': 'ruby', 'C': 'java'} B =. popitem () print (a) print (B) a = {'A': 'python', 'B': 'ruby', 'C ': 'java'} del a # print ('other dictionary method') a = {'first': 'python'} B = dict. fromkeys (['A', 'B'], ['test']) print (a) print (B) print ('dictionary traversal ') a = {'A': 'python', 'B': 'ruby', 'C': 'java'} for I, j in. items (): print (I, j) for I in a: # efficiency is higher than print (I, a [I])

 

String

List only a few simple applications

Print ('join string merging method') a = ['python', 'ruby', 'java'] B = ''. join (a) print (B) c = '*'. join (a) print (c) print ('string common method') a = 'python py' print (. count ('P') print (. capitalize () print ("format output") a = "my favorite book {name} and {name2}" print (. format_map ({'name': 'python', 'name2': 'java'}) print (. format (name = 'shell', name2 = 'bash') print (. isdigit ())

 

 

PS:

The data type in the early stage is only the foundation. If you have mastered the commonly used built-in functions, you can continue to consolidate the basic syntax when learning functions and object advanced topics.

When I was reading python at work today, I was despised by c ++'s development. It's too simple to say. Well, let's continue to work.

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.