Comments
# start comment lines with the # character """ Three quotation marks can comment on multiple lines of three quotation marks can be commented on multiple lines three quotation marks can be commented on multiple lines "" "
Primitive data types and operators (1) Integral type
# integer 3 #=>3
(2) Arithmetic operations
#additionUp#=>2#Subtraction8-1#=>7#multiplication10*2#=>20#Division!!! Results are automatically converted to floating point numbers35/5#=>7.05/3#=>1.6666666666666667#integer Division!!! Result rounding down5//3#=>15.0//3.0#=>1.0-5//3#=>-25//(-3)#=>-2-5.0//3.0#=>-2.0#the result of floating-point numbers is also a floating-point number3*2.0#=>6.0#Take the mold7%3#=>1#x's y-square2**4#=>16#Prioritize with parentheses(1+3) * *#=>8
(2) Boolean operations and comparison operations
#Boolean valueTrue#=>trueFalse#=>false#use not to take non- notTrue#=>false notFalse#=>true#logical operators, note and and or are both lowercaseTrue andFalse#=>falseTrueorFalse#=>true#integers can also be used as Boolean values0== False#=>true2==true#=>false1==true#=>true#To judge equality by = =1==1#=>true2==1#=>false#use! = Judgment Unequal1!=1#=>false1!=2#=>true#Compare Size1<10#=>true#Compare Size1<10#=>true2<=2#=>true2>=2#=>true
(4) Arithmetic operations
#strings can be enclosed in single quotes and double quotes .'This is a string .'"This is also a string"#concatenate strings with a plus sign'Hello'+' World' #= ' Hello world '#string can be used as a list of characters'This is a string'[0]#= ' T '#format a string with format"{} can be {}". Format ("string",'interpolated')#= = ' string can be interpolated '#can repeat parameters to save time"{0} be nimble,{0} is quick,{0} jump over the {1}". Format ("Jack","Candle Stick")#= ' Jack be Nimble,jack is quick,jack jump over the candle stick '#If you do not want to count parameters can use keywords"{name} wants to eat {food}". Format (name='Bob', food='Lasagna')#= ' Bob wants to eat lasagna '#If your Python3 program also runs under Python2.5, you can also use the old format syntax"%s can be%s the%s from"%('Strings','Interpolater',' Old')#= ' strings can interpolater the old '
(2) None
#None is an objectNone#do not use = = when comparing with none, use Is,is to compare whether two variables point to the same object'etc' isNone#=>falseNone isNone#=>true#none,0, empty strings, empty lists, empty dictionaries are all false, others are trueBOOL (None)#=>falseBOOL (0)#=>falsebool"")#=>falseBOOL ({})#=>falseBOOL ([])#=>false
Python Quick Start _1