Python3 列表List reverse 方法
Python3 列表List reverse 方法 #!/usr/bin/python3 list1 = ['physics', 'Biology', 'chemistry', 'maths'] list1.reverse() print ("list now : ", list1)
阅读全文 ↗Python3 列表List reverse 方法 #!/usr/bin/python3 list1 = ['physics', 'Biology', 'chemistry', 'maths'] list1.reverse() print ("list now : ", list1)
阅读全文 ↗Python3 列表List remove 方法 #!/usr/bin/python3 list1 = ['physics', 'Biology', 'chemistry', 'maths'] list1.remove('Biology') print ("list now : ", list1) list1.remove('maths') print ("list now : ", list1)
阅读全文 ↗Python3 列表List Ppop 方法 #!/usr/bin/python3 list1 = ['physics', 'Biology', 'chemistry', 'maths'] list1.pop() print ("list now : ", list1) list1.pop(1) print ("list now : ", list1)
阅读全文 ↗Python3 列表List insert 方法 #!/usr/bin/python3 list1 = ['physics', 'chemistry', 'maths'] list1.insert(1, 'Biology') print ('Final list : ', list1)
阅读全文 ↗Python3 比较运算符 #!/usr/bin/python3 a = 21 b = 10 if ( a == b ): print ("Line 1 - a is equal to b") else: print ("Line 1 - a is not equal to b") if ( a != b ): print ("Line 2 - a is not equal to b") else: print ("Line 2 - a is equal to b") if ( a < b ): print ("Line 3 - a is less than b" ) else: print ("Line 3 - a is not less than b") if ( a > b ): print ("Line 4 - a is greater than b") else: print ("Line 4 - a is not greater than b") a,b=b,a #values of a and b swapped. a becomes 10, b becomes 21 if ( a <= b ): print ("Line 5 - a is either less than or equal to b") else: print ("Line 5 - a is neither less than nor equal to b") if ( b >= a ): print ("Line 6 - b is either greater than or equal to b") else: print ("Line 6 - b is neither greater than nor equal to b")
阅读全文 ↗Python3 列表List Index 方法 #!/usr/bin/python3 list1 = ['physics', 'chemistry', 'maths'] print ('Index of chemistry', list1.index('chemistry')) print ('Index of C#', list1.index('C#'))
阅读全文 ↗Python3 列表List Extend 方法 #!/usr/bin/python3 list1 = ['physics', 'chemistry', 'maths'] list2 = list(range(5)) #creates list of numbers between 0-4 list1.extend(list2) print ('Extended List :', list1)
阅读全文 ↗Python3 列表List Count 方法 #!/usr/bin/python3 aList = [123, 'xyz', 'zara', 'abc', 123]; print ("Count for 123 : ", aList.count(123)) print ("Count for zara : ", aList.count('zara'))
阅读全文 ↗Python3 列表List Append 方法 #!/usr/bin/python3 list1 = ['C++', 'Java', 'Python'] list1.append('C#') print ("updated list : ", list1)
阅读全文 ↗Execute Python-3 Online #!/usr/bin/python3 aTuple = (123, 'C++', 'Java', 'Python') list1 = list(aTuple) print ("List elements : ", list1) str = "Hello World" list2 = list(str) print ("List elements : ", list2)
阅读全文 ↗Python3 list min 方法 #!/usr/bin/python3 list1, list2 = ['C++','Java', 'Python'], [456, 700, 200] print ("min value element : ", min(list1)) print ("min value element : ", min(list2))
阅读全文 ↗Python3 列表List Max 方法 #!/usr/bin/python3 list1, list2 = ['C++','Java', 'Python'], [456, 700, 200] print ("Max value element : ", max(list1)) print ("Max value element : ", max(list2))
阅读全文 ↗