First of all, the tuple, the tuple jokingly said that is with the chain of the sequence, the reason is because the tuple does not go to the sequence as arbitrary a series of operations on its elements, once a tuple is defined, the elements in the tuple can not be arbitrarily changed.
Tuple definition: Tuple name = (,,,,,,)
Note that the tuple's flag is not (), but rather,
Ganso said so much, then add the string formatting problem.
Do not wordy, directly on the dry.
#字符串的格式化print ("------Use of the Format function------") #Format函数含有未知参数和关键字参数 #replacement field with {} instead of # preceded by an unknown parameter, followed by the keyword parameter print ("{0} Love {1} {2} ". Format (" I "," FISHC "," com ")) print (" \ n ") #关键字参数 # The following is an error because the compiler does not know which a,b,c corresponds to who #print (" {A} love {b} {c} ". Format ("I", "FISHC", "com")) print ("{A} love {b} {c}". Format (a= "I", b= "FISHC", c= "com") #或者将关字参数与未知参数混合起来使用, but # The unknown parameter is to print ("\ n") print ("{0} love {b} {c}") in front of the keyword parameter ("\ n") #使用转义字符打印花括号print ("\ R") print ("\ b="), "{{0 }} ". Format (" Escape print curly Braces ") #冒号表示格式化的开始print (" {0:.1f}{1} ". Format (27.658," GB "))
The result of the output is:
Again the sequence of related problems, the sequence is a list, tuples, strings collectively, the reason why they put together three, because there are some similarities between them. Today the main learning is the sequence of built-in functions, directly on the dry.
#序列序列 # List tuple strings are collectively known as the Sequence #list () function to convert an iterative object to a list # if there are no arguments, an empty list is generated # If there is a parameter, the parameter is an iterator print ("Using the list () function to generate an empty listing") a=list (); Print (A, "\ n") #list函数的过程可以理解为先建立一个空的序列 # then use the For loop to move the element into the new sequence by using the Index function print ("Use list (iterator) function to generate a non-empty listing") a= "I Love You" Atolist=list (a) print (atolist) print ("\ n") #tuple ([iterator]) converts an iterative object to a tuple atotuple=tuple (a) print (atotuple) print ( "\ n") #str (obj) function: Converts an Obj object to a string, forcing a type conversion #len (sub) function: Returns the length of a sequence #max (), the min () function guarantees a uniform data type in a sequence #max () function: Returns the maximum value in a sequence or parameter set print (Max (1,2,3,4,5)) #min () function: Returns the maximum value in a sequence or parameter collection #sum (Iterable[,start=0]) returns the sum of the sequence iterable and optional argument start # The data types in the series must also be consistent, Must be a digital print ("\ n") tuple1= (1,2,3,4,5) print (sum (tuple1)) print ("\ n") #**sorted** function to sort the sequence, from small to large by default Note with the list of built-in functions sort differentiates list1=[1,5,4,3,6]list1=sorted (list1) print (list1) print ("\ n") #**reversed () * * To implement the reversal of sequence elements, but not to return a sequence # Note the built-in function with the list reverse () differentiates # Instead of an iterative object print (Reversed (list1)) print ("\ n") #我们可以将返回的迭代器的对象作为list (iterator) parameter # Returns a list of print (List (Reversed (list1))) print ("\ n") #zip合成序列a =[1,2,3,4,5,6,7,8]b=["A", "B", "C", "D"]zip (A, B) print (List (zip (b)))
The program runs as follows:
The main thing is to remember the use of functions, there is no need to cost brain cells.
The above is the Python 0 basic introduction of the format of the five strings and the contents of the sequence of built-in functions, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!