python 自我检测题--part 2

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

capitalize()

2. 

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. 

8. 

9. 

10. 

11. 

为什么 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. 

14. 

相关推荐

  1. 网络编程part2

    2024-02-10 07:44:03       26 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-02-10 07:44:03       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-02-10 07:44:03       106 阅读
  3. 在Django里面运行非项目文件

    2024-02-10 07:44:03       87 阅读
  4. Python语言-面向对象

    2024-02-10 07:44:03       96 阅读

热门阅读

  1. web3之跨链合成资产交易协议LINA (Linear)

    2024-02-10 07:44:03       56 阅读
  2. 力扣0124——二叉树的最大路径和

    2024-02-10 07:44:03       51 阅读
  3. 算法刷题day10

    2024-02-10 07:44:03       47 阅读
  4. STL - 容器适配器

    2024-02-10 07:44:03       54 阅读
  5. 数据分类分级

    2024-02-10 07:44:03       45 阅读
  6. (52)只出现一次的数字III

    2024-02-10 07:44:03       59 阅读
  7. 深入解析 Spring 和 Spring Boot 的区别

    2024-02-10 07:44:03       56 阅读