Python data feature escape and operator summary-ten Day

Source: Internet
Author: User

One, assignment operators

The assignment operation assigns the value of a to a value, and the result of the operation is assigned to B.

Second, comparison operators

The result of the comparison operation returns a bool value, True and false, which is typically used to control the process of executing the program, such as the following code:

1 if a = = B:23  execute print (...) 4 5 Else : 6 7 Execute print (----)

Third, logical operation

The logical operation returns the result as a Boolean value, and the control program calculates that the X and C:and are true after the truth; A and B or C:and is false to calculate whether or is true, for true continuation operation, false for false; Not a = B: meaning a! = B

IV. member Operations

Member operations are primarily used to determine whether an element is in a collection of elements:

1A ="ABCDEFG"2b ="a"3 ifBinchA:4     Print("b in the sequence of a")5 Else:6     Print("B is not in the sequence of a")

Data type function: int,str,list,dict,tuple; all have indexing and slicing capabilities.

Number (int)

Python can handle positive and negative integers of any size, but it is actually related to the memory of our computer, on a 32-bit machine, the number of integers is 32 bits, the value range is -2**31~2**31-1, on a 64-bit system, the number of integers is 64 bits, the value range is -2**63~2** 63-1.

1A = 42 Print(A.bit_length ())3Bit_length (self):#real signature unknown; restored from __doc__4         """5 int.bit_length () int6         7 Number of bits necessary to represent self in binary.8 >>> Bin (Panax Notoginseng)9 ' 0b100101 'Ten >>> (PNS). Bit_length () One 6 A         """ -         return0
A = "4"
Page print (int (a)) #讲字符串 "4" converted to an integer 4
16

String (str)

The following are commonly used string functions

1s="abcdef GHG k"2 Print(S.title ())#Convert string to title, output Abcdef Ghg K3  4 Print(S.capitalize ())#capitalize the first letter of the string, output Abcdef GHG k5  6 Print(S.count ('D', 0,len (s)))#calculates the number of occurrences of the substring ' d ' in the parent string, which is found by default in the entire parent string,7                     #you can specify the starting position in the following two parameters, where I have specified the lookup in (0,len (s)),8                     #where Len (s) stands for string length9  Ten Print(S.startswith ('a'))#to determine if a string starts with something, output true here, One   A Print(S.find ('g', 0,len (s)))#finds the first occurrence of a substring in a string, where it outputs 7, and can also specify a range of positions to search -   - Print(S.upper ())#Convert the string to uppercase, here output abcdef GHG K the   - Print(S.join (['a','b','C']))#use string s to connect list [' A ', ' B ', ' C '] output aabcdef GHG kbabcdef GHG KC -   - Print(S.strip ())#Remove both spaces +   - Print(S.split ())#split the string, return a list here output [' abcdef ', ' GHG ', ' K '] +   A Print(S.replace ('g','G', 1))#Replace, replace all by default, can be set to 1, replace only once, here only once output abcdef GHG k at   - Print(S[0:4])#slice, [0:4] represents the first 4 bits of the string s to be taken out, here output ABCD

Listing (list)

A list is a python built-in data type is a list, an ordered set of elements that can be added and removed at any time.

1l=['a','b','cc', 4]#Define a list2  3L.append (5)#add an element, l=[' A ', ' B ', ' CC ', 4, 5]4  5L.pop ()#remove an element from the tail, l=[' A ', ' B ', ' CC ', 46  7L.remove ('a')#remove ' A ' from the list, l=[' B ', ' CC ', 4]8  9L.extend (['GG','KK'])#Add a list [' GG ', ' KK '], l=[' B ', ' CC ', 4, ' GG ', ' KK 'Ten   OneL.reverse ()#invert a list, l=[' KK ', ' GG ', 4, ' cc ', ' B '] A   - Print(L.count ('KK'))#number of occurrences of an element output 1 -   the Print(L.index ('GG'))#the position where the element appears, Output 1 -   -  forIinchL#looping out list elements -     Print(i) +   - Print(L[0:4:2])#list slices, increment by step 2, Output [' KK ', 4]

Tuple (tuple)

Tuple and list are very similar, but once the tuple initialization can not be modified, the tuple is also ordered, the tuple uses the parentheses identifier; The first-level elements of a tuple cannot be modified, deleted, or child elements can be modified.

1T= ('a','b','b','C')#Define a tuple2  3 Print(T.index ('b'))#index The first occurrence of the element, you can also specify a range to find, here by default in the entire tuple lookup output 14  5 Print(T.count ('b'))#count the number of occurrences of the element, here Output 26  7 Print(Len (t))#output The length of the far group, here output 48  9  forIinchT:Ten     Print(i)#cycle through the tuple data One   A Print(T[1:3])#Slice output (' B ', ' B ')

Dictionary (dict)

Dictionaries are unordered, using key-value (Key-value) storage, with extremely fast lookup speeds.

1D = {'Michael': 95,'Bob': 75,'Tracy': 85}2  3D.get ('Bob')#based on key to get values, if not present returns NONE, here output4  5D.pop ('Bob')#Delete an element by key d={' Michael ': ' Tracy ':6  7d['Jason']=99#new element d={' Michael ': Up, ' Tracy ': ' Jason ': the8  9 Print(Len (d))#Output dictionary length, here output 3Ten   One Print('Jason' inchD#Python3 Remove Has_key, to determine if the key exists in A   -  forIinchD: -     Print(i)#loop default key Output the   -  forIinchD.values ():#looping by value output -     Print(i) -   +  forKvinchD.items ():#cyclic key value output -     Print(K,V)

Python data feature escape and operator summary-ten Day

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.