Python Quick Start _1

Source: Internet
Author: User
Tags arithmetic integer division logical operators

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.