All types such as: one basic data type 1) digital type copy code >>> 2/2+2*25.0>>> (50-5*6)/45.0>>> 8/51.6>>> 8//51> >> x=y=1.5>>> x*y2.25 Copy code Note:/means to convert first to double and then in addition to the operation, but//to convert without double, which is equivalent to dividing two integers. 2) String type Copy code >>> ' Hello World ' ' Hello World ' >>> ' Hello World ' ' Hello World ' >>> ' doesn ' " doesn ' t ' >>> ' Hello Tom ' ' ' Hello ' tom ' >>> ' hello,\ ' tom\ ' ' ' Hello, ' Tom ' ' >>> hello= ' hello,i Miss you. " >>> print (hello) hello,i Miss You.>>> print (r "hello\n World") hello\n world>>> word= ' Hello ' + ' A ' >>> print (word) helloa>>> word[0:5]+ ' B ' Hellob ' >>> word[-1] ' A ' >>> len (word) 6 Copy Code Note: Single quotation marks "and double quotes" "function the same, are used to denote a string, but the single quotation mark" "can have double quotation marks" ", double quotes" "can also have single quotation marks", but if the double quotation mark "" in the use of double quotation marks "" or single quotation marks "in the use of single quotation marks", For example, \ ' or \ '. Line end \ indicates string wrapping. The r before the string represents a pure string, at which time the escape character in the string is invalidated. + Represents a link to a string. [] can be used to index characters in a string, but cannot be used to modify characters in a string. Len () is used to get the length of the string. 3) List Copy code >>> a = [' Money ', ' money ', ' money ', 100000000]>>> a[' money ', ' money ', ' money ', 100000000]>>> a[3]100000000>>> a[-1] = a[-1] * 2>>> a[-1]200000000>>> [' i ', ' want '] + a[' i ', ' want ', ' money ', ' money ', ' money ', 200000000]>>> a[' money ', ' money ', ' money ', 200000000]>>> a[ : 0] = [' I ', ' Want ']>>> a[' i ', ' want ', ' money ', ' money ', ' money ', 200000000]>>> a[2:4] = []>>> A [' I ', ' want ', ' money ', 200000000]>>> Len (a) 4>>> a[:]= []>>> a[]>>> Copy Code Note: The list can contain any different data types. [] You can modify the elements in the list. + can be used to merge the list. =[] can be used to delete certain elements in the list. Len can be used to get the length of the list. Two Process Control keywords Note: Python uses a colon: and the space before the statement to indicate the start and end of the block of statements represented by {and} in other languages. 1) if/else copy code x = Int (input ("Please enter a integer:")) if x < 0:x = 0 print (' negative changed to zero ') elif x = = 0:p Rint (' Zero ') elif x = = 1:print (' a ') else:print (' more ') Copy code 2) for copy Code a = [' Cat ', ' window ', ' defenestrate ']for x in a[1: ]: Print (x, Len (x)) if Len (x) > 6:a.insert (0, x) print (a) b = [' Mary ', ' had ', ' a ', ' little ', ' lamb ']for i in range (len (b ): Print (I, b[i]) copyCode 3) Whilea, b = 0, 1while b < 10:print (b) A, B = B, a+b4) continue/break/pass copy code for I in range: if (i%5 = = 0): pri NT (i); Continue Elif (i >=): print ("over"); Break Else:pass;print ("Thanks") Copy Code Note: Pass is equivalent to an empty statement.
Python Note 2.1