Python3 列表List Len 方法
Python3 列表List Len 方法 #!/usr/bin/python3 list1 = ['physics', 'chemistry', 'maths'] print (len(list1)) list2 = list(range(5)) #creates list of numbers between 0-4 print (len(list2))
阅读全文 ↗Python3 列表List Len 方法 #!/usr/bin/python3 list1 = ['physics', 'chemistry', 'maths'] print (len(list1)) list2 = list(range(5)) #creates list of numbers between 0-4 print (len(list2))
阅读全文 ↗Python3 删除列表 #!/usr/bin/python3 list = ['physics', 'chemistry', 1997, 2000] print (list) del list[2] print ("After deleting value at index 2 : ", list)
阅读全文 ↗Python3 更新列表 #!/usr/bin/python3 list = ['physics', 'chemistry', 1997, 2000] print ("Value available at index 2 : ", list[2]) list[2] = 2001 print ("New value available at index 2 : ", list[2])
阅读全文 ↗Python3 算术运算符 #!/usr/bin/python3 a = 21 b = 10 c = 0 c = a + b print ("Line 1 - Value of c is ", c) c = a - b print ("Line 2 - Value of c is ", c ) c = a * b print ("Line 3 - Value of c is ", c) c = a / b print ("Line 4 - Value of c is ", c ) c = a % b print ("Line 5 - Value of c is ", c) a = 2 b = 3 c = a**b print ("Line 6 - Value of c is ", c) a = 10 b = 5 c = a//b print ("Line 7 - Value of c is ", c)
阅读全文 ↗Python3 字典 #!/usr/bin/python3 dict = {} dict['one'] = "This is one" dict[2] = "This is two" tinydict = {'name': 'john','code':6734, 'dept': 'sales'} print (dict['one']) # Prints value for 'one' key print (dict[2]) # Prints value for 2 key print (tinydict) # Prints complete dictionary print (tinydict.keys()) # Prints all the keys print (tinydict.values()) # Prints all the values
阅读全文 ↗Python3 元组 #!/usr/bin/python3 tuple = ( 'abcd', 786 , 2.23, 'john', 70.2 ) tinytuple = (123, 'john') print (tuple) # Prints complete tuple print (tuple[0]) # Prints first element of the tuple print (tuple[1:3]) # Prints elements starting from 2nd till 3rd print (tuple[2:]) # Prints elements starting from 3rd element print (tinytuple * 2) # Prints tuple two times print (tuple + tinytuple) # Prints concatenated tuple
阅读全文 ↗Python3 列表 #!/usr/bin/python3 list = [ 'abcd', 786 , 2.23, 'john', 70.2 ] tinylist = [123, 'john'] print (list) # Prints complete list print (list[0]) # Prints first element of the list print (list[1:3]) # Prints elements starting from 2nd till 3rd print (list[2:]) # Prints elements starting from 3rd element print (tinylist * 2) # Prints list two times print (list + tinylist) # Prints concatenated lists
阅读全文 ↗Python3 字符串 #!/usr/bin/python3 str = 'Hello World!' print (str) # Prints complete string print (str[0]) # Prints first character of the string print (str[2:5]) # Prints characters starting from 3rd to 5th print (str[2:]) # Prints string starting from 3rd character print (str * 2) # Prints string two times print (str + "TEST") # Prints concatenated string
阅读全文 ↗Python3 为变量赋值 #!/usr/bin/python3 counter = 100 # An integer assignment miles = 1000.0 # A floating point name = "John" # A string print (counter) print (miles) print (name)
阅读全文 ↗Python3 注释 #!/usr/bin/python3 # First comment print ("Hello, Python!") # second comment
阅读全文 ↗