# ! / Usr / bin / to python3 counter = 100 # Integer Variable Miles = 1000.0 # float variable name = " runoob " # string Print (counter) Print (Miles) Print (name)
# ! / Usr / bin / to python3 STR = ' Runoob ' Print (STR) # output string Print (STR [0: -1]) # output of the first up to the last of the characters in the second Print (STR [0] ) # output of the first character Print (STR [2:. 5]) # output from the start of the third through fifth characters Print (STR [2:]) # output from all of the start of the third character Print (STR * 2) # output string twice Print (STR + " the TEST " ) # connection string
# ! / Usr / bin / to python3 List = [ ' ABCD ' , 786, 2.23, ' runoob ' , 70.2 ] tinylist = [123, ' runoob ' ] Print (List) # outputs the complete list Print (List [0]) # outputting a first list element Print (list [. 1:. 3]) # the second output to the third element starts from Print (list [2:]) # all elements of the output from the third element starts Print (tinylist * 2) # outputted twice listing Print (list tinylist +) # Connection List
DEF reverseWords (INPUT): # by spaces string delimiter, separated into the individual word list inputWords input.split = ( " " ) # Flip string # Suppose = list List [1,2,3,4], # list [0] = 1, list [1] = 2, and -1 is the last element of the list [-1] = 4 (list [3] = 4 Like) # inputWords [-1 :: -. 1] three parameters # the first parameter -1 is the last element of # the second parameter is blank, is moved to the end of the list # third parameter steps, -1 represents the reverse inputWords inputWords = [-1 :: -. 1 ] # recombining string Output = ' ' .join (inputWords) return Output IF the __name__ == "__main__": input = 'I like runoob' rw = reverseWords(input) print(rw)
# ! / Usr / bin / to python3 tuple = ( ' ABCD ' , 786, 2.23, ' runoob ' , 70.2 ) tinytuple = (123, ' runoob ' ) Print (tuple) # outputs the complete tuple Print (tuple [0]) # first tuple element output Print (tuple [. 1:. 3]) # output from the second element to the third element starts Print (tuple [2:]) # output start from the third element of all elements Print (tinytuple * 2) # outputted twice tuple Print (+ tinytuple tuple)# Connection tuples
# ! / Usr / bin / to python3 Student = { ' Tom ' , ' Jim ' , ' Mary ' , ' Tom ' , ' Jack ' , ' Rose ' } Print (Student) # output set, repetitive elements are automatically removed # members of the test IF ' Rose ' in Student: Print ( ' Rose in the collection ' ) the else : Print ( 'Rose not in the set ' ) # SET set operation is A = SET ( ' Abracadabra ' ) b = SET ( ' alacazam ' ) Print (A) Print (A - b) # A and b difference set Print (A | b ) # a and b and set Print (a & b) # a and the intersection b Print (a ^ b) # a and b are not simultaneously present in the element
# ! / Usr / bin / to python3 dict = {} dict [ ' One ' ] = " . 1 - novice Tutorial " dict [ 2] = " 2 - novice Tools " tinydict = { ' name ' : ' runoob ' , ' code ' :. 1, ' Site ' : ' www.runoob.com ' } print (dict [ ' One ' ]) # output key is 'one' value print(dict [2]) # outputs a key value 2 Print (tinydict) # outputs the complete dictionary Print (tinydict.keys ()) # outputs all keys Print (tinydict.values ()) # output all the values