面试

3.

函数                      描述

  int(x [,base ])         x转换为一个整数

  long(x [,base ])        x转换为一个长整数

  float(x )               x转换到一个浮点数

  complex(real [,imag ])  创建一个复数

  str(x )                 将对象 x 转换为字符串

  repr(x )                将对象 x 转换为表达式字符串

  tuple(s )               将序列 s 转换为一个元组

 list(s )                将序列 s 转换为一个列表

 chr(x )                 将一个整数转换为一个字符

 ord(x )                 将一个字符转换为它的整数值

 hex(x )                 将一个整数转换为一个十六进制字符串

 oct(x )                 将一个整数转换为一个八进制字符串

1

python

A0 = dict(zip(('a','b','c','d','e'),(1,2,3,4,5)))

A1 = range(10)

A3 = {i:i*i for i in A1}

A4 = [[i,i*i] for i in A1]

python

A0 = {'a': 1, 'c': 3, 'b': 2, 'e': 5, 'd': 4}

A1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

A3 = {0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81}

A4= [[0, 0], [1, 1], [2, 4], [3, 9], [4, 16], [5, 25], [6, 36], [7, 49], [8, 64], [9, 81]]

2.软硬链接区别?

软连接类似windows的快捷方式,当删除源文件,那么软链接失效。硬链接可以理解为源文件的一个别名。多个别名所代表的是同一个文件。当rm一个文件的时候,那么此文件的硬链接数减1,当硬链接数为0的时候,文件删除。

4.Python里面如何生成随机数?random模块

随机整数:random.randint(a,b):返回随机整数x,a<=x<=b

random.randrange(start,stop,[,step]):返回一个范围在(start,stop,step)之间的随机整数,不包括结束值。

随机实数:random.random( ):返回01之间的浮点数

random.uniform(a,b):返回指定范围内的浮点数。

5.以下的代码的输出将是什么? 说出你的答案并解释。

class Parent(object):

    x = 1

class Child1(Parent):

    pass

class Child2(Parent):

    pass

print Parent.x, Child1.x, Child2.x

Child1.x = 2

print Parent.x, Child1.x, Child2.x

Parent.x = 3

print Parent.x, Child1.x, Child2.x

1 1 1
1 2 1
3 2 3

原文地址:https://www.cnblogs.com/liuyibo007/p/10178854.html