python quiz 1-24

 

Q1:   def F(b, c): pass

1.     定义一个列表并且初始化

2.       定义一个函数,这个函数什么都不做

3.     定义一个函数,其参数传递通过

4.     定义一个空类

Q2:   print type (1/2)

1.     <type ‘int’>

2.       <type ‘number’>

3.     <type ‘float’>

4.     <type ‘double’>

5.     <type ‘tuple’>

Q3:   print type (1.0/2)

1.     <type ‘int’>

2.       <type ‘number’>

3.     <type ‘float’>

4.     <type ‘double’>

5.     <type ‘tuple’>

Q4:   print type ([1,2])

1.     <type ‘tuple’>

2.       <type ‘int’>

3.     <type ‘set’>

4.     <type ‘complex’>

5.     <type ‘list’> 

Q5:   def f():pass

         print type(f())

1.     <type ‘tuple’>

2.       <type ‘function’>

3.     <type ‘NoneType’>

4.     <type ‘str’>

5.     <type ‘type’>

Q6:   def f():pass

         print type(f)

1.     <type ‘tuple’>

2.       <type ‘function’>

3.     <type ‘NoneType’>

4.     <type ‘str’>

5.     <type ‘type’>

Q7:   print type(2+3J)

1.     <type ‘tuple’>

2.       <type ‘complex’>

3.     <type ‘unicode’>

4.     <type ‘str’>

5.     <type ‘dict’>

Q8:   print type(lambda:None)

1.     <type ‘NoneType’>

2.       <type ‘tuple’>

3.     <type ‘type’>

4.     <type ‘function’>

5.     <type ‘bool’>

Q9:   print len([1,2,3,None,(),[],])

1.     Syntax error

2.       4

3.     5

4.     6

5.     7

Q10:   d = lambda p: p * 2

           t = lambda p: p * 3

           x = 2

           x = d(x)

           x = t(x)

           x = d(x)

           print x

1.     48

2.       7

3.     12

4.     24

5.     36

 

 Q11:   x=4.5

            y=2

            print x//y

1.     2.0

2.       2.25

3.     9.0

4.     20.25

5.     21

Q12:   print len(set([1,1,2,3,3,3,3,4,5,5]))

1.     3

2.       5

3.     7

4.     10

5.     12

Q13:   x=True 

           y=False

           z=False

           if x or y and z:

               print “yes”

           else:

               print “no”

1.     yes

2.       no

3.     fails to compile

Q14:   x = True 

           y = False

           z = False

           if not x or y:

                  print 1

           elif not x or not y and z:

                  print 2 

           elif not x or y or not y and x:

                  print 3

           else:

                   print 4

1.     1

2.       2

3.     3

4.     4

5.     5

Q15:    daysOfWeek = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] 

           months =  ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']

            print "DAYS: %s, MONTHS %s" % (daysOfWeek, months)

       上述的代码能否成功输出星期一到星期天以及一月到十二月吗?

1.     True

2.     False

Q16:   f = None  

for i in range (5): 

          with open("data.txt", "w") as f:

              if i > 2:

                  break

          print f.closed

1.     True

2.     False

3.     None

Q17:   counter = 1   

            def doLotsOfStuff(): 

                    global counter

                    for i in (1, 2, 3):

                       counter += 1

            doLotsOfStuff()

            print counterTrue

1.     1

2.     3

3.     4

4.     7

5.     None of the above

Q18:   print r”nwoow”

1.     new line then the string: woow

2.     the text exactly like this: r"nwoow"

3.     the text like exactly like t