python 自我检测题--part 2

1. Which of the following function capitalizes first letter of string?

capitalize()

2. 

  • Iterate through dictionary keys: keys()
  • Iterate through dictionary values: values()
  • Iterate through dictionary key-value pairs: items()

3.  Which of the following function convert a single character to its integer value in python?

ord(x)

The ord() function returns the number representing the unicode code of a specified character.

4. - What is output for − min(''hello world'')

a blank space character

Explanation

python considers a blank space character as minimum value in a string

5. What is output of following code −

a = (1, 2)
a[0] +=1

 Type Error

Explanation

TypeError − ‘tuple' object does not support item assignment because a tuple is immutable.

6. Which of the following function checks in a string that all characters are titlecased?

Explanation

istitle() − Returns true if string has at least 1 character and all characters are titlecased.

  • Use the Python string title() method to returns the titlecased version of a string.

7. python 自我检测题--part 2_第1张图片

python 自我检测题--part 2_第2张图片

8. 

python 自我检测题--part 2_第3张图片

9. python 自我检测题--part 2_第4张图片

10. 

python 自我检测题--part 2_第5张图片

python 自我检测题--part 2_第6张图片

11. 

python 自我检测题--part 2_第7张图片

python 自我检测题--part 2_第8张图片

为什么 1.0 == 1 返回 True,1.0 is 1 返回 False,is 和 == 应该怎么理解和区别呢?

Python 中的对象包含三要素:id、type、value:

id 用来唯一标识一个对象,即在内存开辟了一块空间暂时存放这个变量

type 标识对象的类型,如之前所说的 int,float,bool,str等

value 就是对象的值

is 判断 a 对象是否是 b 对象,是通过 id 来判断的

== 判断的是 a 对象的值是否等于 b 对象的值,是通过 value 来判断的

注意:再次强调,Python 中,1 == 1.0 返回 True 是由于只比较他们的值,不考虑他们的精度,1 和 1.0 只是精度不同

12. What is the following function inserts an object at given index in a list?

list.insert(index, obj)

13. python 自我检测题--part 2_第9张图片

14. 

python 自我检测题--part 2_第10张图片

python 自我检测题--part 2_第11张图片

python 自我检测题--part 2_第12张图片

你可能感兴趣的:(python,css,html)