python 趣味问题之一
1.python 里,写中文必须加什么,才会不报错?
-
在用Python读网页或文档时,最好统一将获取的内容统一转换成什么编码?
-
Python 可以同一行显示多条语句吗?
-
以单下划线开头 的代表什么?
-
以双下划线开头的 __foo 代表什么;以双下划线开头和结尾的 foo 代表 什么?
-
所有 Python的关键字是小写还是大写?
-
lambda是Python中的保留字符吗?
-
使用什么符号将一行的语句分为多行显示?
-
不换行输出怎么表示?
-
0x69,10;-4721885298529L,70.2E-12;4.53e-7j,以上分别是什么符号类型?
-
int(x [,base ])
long(x [,base ])
float(x )
complex(real [,imag ])
str(x )
repr(x )
eval(str )
tuple(s )
list(s )
chr(x )
unichr(x )
ord(x )
hex(x )
oct(x ) 试解释以上各条命令。
abs(-10) 返回 多少
-
math.ceil(4.1) 返回 什么
-
cmp(x, y)
,如果 x < y 返回 多少, 如果 x == y 返回 几, 如果 x > y 返回 什么
-
math.exp(1) 返回 多少
-
math.fabs(-10) 返回几
-
math.floor(4.9)返回 什么
-
math.log(math.e)返回什么?
-
math.log(100,10)返回什么
-
math.log10(100)返回 几
-
试解释以下函数
max(x1, x2,…)
min(x1, x2,…)
modf(x)
pow(x, y)
round(x [,n])
sqrt(x)
22… 解释以下函数
choice(seq)
randrange ([start,] stop [,step])
random()
seed([x])
shuffle(lst)
uniform(x, y)
23… 解释以下函数
acos(x)
asin(x)
atan(x)
atan2(y, x)
cos(x)
hypot(x, y)
sin(x)
tan(x)
degrees(x)
radians(x)
24…解释以下符号
%c
%s
%d
%u
%o
%x
%X
%f
%e
%E
%g
%G
%p
- 试写出以下命令输出结果
len([1, 2, 3])
[1, 2, 3] + [4, 5, 6]
[‘Hi!’] * 4
- 试写出以下命令输出结果
3 in [1, 2, 3]
for x in [1, 2, 3]: print x,
- 试预测下列表达式的结果
>>> 2 + 2
>>> 50 - 5*6
>>> (50 - 5*6) / 4
>>> 8 / 5
>>> 17 / 3 # classic division returns a
>>>
>>> 17 // 3 # floor division discards the fractional part
>>> 17 % 3 # the % operator returns the remainder of the division
>>> 5 * 3 + 2 # result * divisor + remainder
>>> 5 ** 2 # 5 squared
>>> 2 ** 7 # 2 to the power of 7
- 写出下列命令的结果
>>> width = 20
>>> height = 5 * 9
>>> width * height
>>> tax = 12.5 / 100
>>> price = 100.50
>>> price * tax
>>> price + _
>>> round(_, 2)
30.试写出下列命令结果
>>> word = 'Python'
>>> word[0] # character in position 0
>>> word[5] # character in position 5
- 试写出下列命令结果
>>> s = 'supercalifragilisticexpialidocious'
>>> len(s)
32.试写出下列命令结果
>>> squares = [1, 4, 9, 16, 25]
>>> squares
>>>
>>> squares[0] # indexing returns the item
>>> squares[:]
>>>
>>> squares + [36, 49, 64, 81, 100]
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
33.试写出下列命令结果
>>> cubes = [1, 8, 27, 65, 125] # something's wrong here
>>> 4 ** 3 # the cube of 4 is 64, not 65!
>>> cubes[3] = 64 # replace the wrong value
>>> cubes
34.试写出下列命令结果
>>> letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
>>> letters
>>> # replace some values
>>> letters[2:5] = ['C', 'D', 'E']
>>> letters
>>> # now remove them
>>> letters[2:5] = []
>>> letters
>>> # clear the list by replacing all the elements with an empty list
>>> letters[:] = []
>>> letters
35.试写出下列命令结果
>>> letters = ['a', 'b', 'c', 'd']
>>> len(letters)
36.试写出下列命令结果
>>> a = ['a', 'b', 'c']
>>> n = [1, 2, 3]
>>> x = [a, n]
>>> x
>>> x[0]
>>> x[0][1]
37.试写出下列命令结果
>>> a, b = 0, 1
>>> while a < 1000:
... print(a, end=',')
... a, b = b, a+b
38.试写出下列命令结果
-3**2
(-3)**2.