tags: # python data structure Input in python
nums = list(map(int, input().strip().split()))
Explain the specific meaning first:
Since INPUT () obtains the string type, turns into integer through the int function;
Since the map returns a iterator, the list is added to a list;
input(). strip(). split():
The function of implementation is divided by space, and multiple data is entered at the same time;
Input input function, and the role of placing (), split () with strip (), split ():
Delete the input head and the space in the tail;
Then the input is divided into multiple according to the space, and returns in the form of a list;
print("\n 1. ----- .strip() method --------\n")
# Delete the leftmost and right side of the string, the specified string,
# As long as the specified characters appear on both sides, they will be deleted. By default, the specification string is a space;
str = " NNN I am a student NNN "
print("*___*", str)
print("*___*", str.strip()) # By default, delete the space at the head and tail;
print("*___*", str.strip(' N')) # Delete the characters specified in the head and tail. Note that if there is a space on the head at this time, the space must be added here;
print("*___*", str.strip(" student")) # Can only be removed, the prescribed characters in the head and tail in the string;
print("\n 2. ----- .split() method --------\n")
# Return to a list, consisting of STR after SP division,; SP default situation is a space;
# str.split( sp, num);
# When the separators are not specified, the default is the space, and it includes the change of the line, the watchmaking \ t, but it cannot be the empty "";
# Num is to generate (NUM + 1) string according to the number of split segments of SP, which is divided according to SP;
str = "\nLine1-abc \nLine2-def \nLine3-ghi \nline4-hahaha line5-nnnn"
print (str.split()) # By default, as long as the default separators are included, the segmentation is divided;
print(str.split(" ",2 ))
print (str.split(' ', 4))
print("\n 3. ----- .input() method --------\n")
# input () function to accept a standard input data and return the String type;
# Since the string type is obtained through INPUT, it turns into integer through int;
# nums1 = list(map(int, input().strip().split()))
print("please input a int list: ")
nums1 = list(map(int, input().strip().split()))
print("output nums1: \n", nums1)
print("\n 4. ----- .map() method --------\n")
# MAP (fun1, Iteraable), according to the FUN1 function, map the Iterable sequence;
# Python3 returns the iterator, you need to add the List to convert the iterator into list;
# list(map(fun2, iterable) )
def fun1(x):
return x*x
print(list(map(fun1, nums1)))
1. Python strip() Syntax description: The Python strip () method is used to remove the characters specified by the beginning and end of a string (the default is a space or newline) or a sequence of ch...
One, strip Description The Python strip() method is used to remove the specified characters at the beginning and end of the string (the default is a space). Grammar strip() method syntax: Parameter ch...
Analysis of split and strip It's not easy to make, and I also kindly ask everyone to like and pay attention, please be careful! Hello everyone, I amAnonymous, Today, I will give you an analysis of the...
strip: When the parameter is empty, the blank characters at the beginning and end will be deleted by default, including ‘\n’,’\r’,’\t’ split: split all by string (s...
Syntax function annotations split() Remove the incision unit and return the disconnected list (if there is a continuous incision unit, each incision unit is removed once, and the continuous incision u...
Recently I often meet this function when I learn deeply learned. Check the relevant knowledge records as follows. parameter: STR - Separator, default is all empty characters, including spaces, wrap (\...
Article catalog Foreword First, Strip () 1. Method 2. Example Second, split () 1. Method 2. Example Summarize Foreword Tip: The following is the textual content of this article, the case is available ...
Strip() function Declaration: s is a string, rm is the sequence of characters to be deleted. The function of this function is to start from the beginning and end of the original character s. As long a...
1. format: formatting function Use the help function: search result: Practical application: Example 1: Example 2: Example 3: Example 4: 2. strip: remove function Use the help function: search result: ...
1.join (), you can str, lsit, tuple, dict use, but can not int, ---------------------------------------------------------------------------------------------------------------- 2.split () split The ou...