zoukankan      html  css  js  c++  java
  • 面试题(七)

    一、单项选择

    (一)   以下叙述正确的是:

    1. continue语句的作用是结束整个循环的执行
    2. 只能在循环体内和switch语句体中使用break语句
    3. 在循环体内使用break语句或continue语句的 作用相同
    4. 从多层循环嵌套中退出时,只能使用goto语句 
    # B
    答案

    (二) Python如何定义一个函数(

    # 3
    答案

    )

    1. class <name> (<Type> arg1 , <Type> arg 2, ... , <Type> argN)
    2. function <name> (arg1 ,arg2 ,… , argN)
    3. def <name> (arg1 ,arg2 ,… , argN)
    4. def <name> (<Type> arg1 , <Type> arg 2, ... , <Type> argN)

    (三) 下面哪个函数能够在Linux环境下创建一个子进程:

    1. os.popen
    2. os.fork
    3. os.system
    4. os.link
    # 2
    答案

    (四) 已知x=43,ch = 'A' ,y = 1,则表达式(x > y and ch< ‘B’ and y)的值是 

    1. 0
    2. 1
    3. 出错
    4. True(“真”)
    # 2
    答案

    (五) 下面的语句哪个会无限循环下去

             启动range函数原型为range([start],stop[,step])

          1、for a in range(10):

                     time.sleep(10)

      2、while 1 < 10:

          time.sleep(10)

      3、while True:

          break;

      4、a = [3,-1, 5 , 7]

        for I in a[:]

               if a > 10:

                 break;

    # 2
    答案

    (六) 下列表达式中返回为True的是:

             A. 3 > 2 >2

             B. ‘abc’ > ‘xyz’

             C. 0x56 < 56

             D. (3,2) < (‘a’,’b’)

    # D
    答案

    (七) Python不支持的数据类型有

    1. char
    2. int
    3. float
    4. list
    # 1
    答案

    二、不定选项

    (一)   下面的函数,那些会输出1,2,3三个数字

    1. for I in range(3)

        print i

      2. aList = [0,1,2]

              for I in aList:

                    print i+1

      3. I = 1

      while I < 3:

             print i

             I = I +1

      4.for I in range(3):

        print I + 1

    # 2,4
    答案

    三、填空题

    (一)   以下函数需要调用在其中引用一个全局变量k,请填写语句:

    def func():

             ___________

             k = k +1

    global k
    答案

    (二) 请把以下函数转化为Python lambda匿名函数

             def add(x,y):

                      return x+y

    lambda x,y:x+y
    答案

    (三) 请简单解释Python中static method(静态方法)和class method(类方法)

    请将以下代码填写完整

    class A(object):
        def foo(self,x):
            print("executing foo(%s,%s)" % (self,x))
    
        @classmethod
        def class_foo(cls,x):
            print("executing class_foo(%s,%s)" % (cls,x))
    
        @staticmethod
        def static_foo(x):
            print("executing static_foo(%s)" % (x))
    a = A()
    # 调用 foo函数,参数传入1
    a.foo(1)
    # 调用class_foo函数,参数传入1
    a.class_foo(1)
    A.class_foo(1)
    # 调用静态方法,传入参数1
    a.static_foo(1)
    A.static_foo(1)
    答案

    四、程序题

    1、 请书写一个函数,用于替换某个字符串的一个或某几个字串

    函数原型 strreplace(str,oldString,newString);

    例如:

    pstr = “Hello World!”

    afterReplaceStr = strreplace(pstr,”World”,”Tom”)

    那么afterReplaceStr的值为”Hello Tom”

    def strreplace(str,oldString,newString):
        return str.replace(oldString,newString)
    答案

    2、 平衡点问题:

    假如一个数组中的元素,其前面的部分等于后面的部分,那么这个点的位序就是平衡点

    比如一个列表 numbers = [1,3,20,2,18,6],2前面的总和为24,2 后面的总和也是24,那么2就是平衡点

    要求编写程序,寻找并返回任意一个列表的平衡点

    def balance_num(numbers):
        for i in range(0,len(numbers)):
            if sum(numbers[:i]) == sum(numbers[i+1:]):
                return numbers[i]
        return None
    答案
  • 相关阅读:
    myeclipse学习总结一(在MyEclipse中设置生成jsp页面时默认编码为utf-8编码)
    使用Android Studio调试UiAutomator过程中遇到的问题
    手游性能之渲染分析2
    手游性能之渲染分析1
    手脱ASProtect v1.23 RC1(有Stolen Code)之以壳解壳
    手脱ASProtect v1.23 RC1(有Stolen Code)
    Java 中extends与implements使用方法
    Java在处理大数据的时候一些小技巧
    Oracle 分页原理
    powerdesigner连接数据库 导出数据
  • 原文地址:https://www.cnblogs.com/skiler/p/6946420.html
Copyright © 2011-2022 走看看