Python复习题库带答案

这篇博客包含了多个Python编程的基础题目及答案,涉及类型检查、对象比较、表达式计算、字符串操作、集合和字典等基础知识。通过这些题目,读者可以巩固Python语法和常用内置函数的理解。
摘要由CSDN通过智能技术生成

1.下列Python语句的输出结果是(  <class NoneType> )

def f():pass    

print(type(f()))

  1. Python语句a,b=3,4;a,b=b,a;print(a,b)的结果是 4 , 3
  2. Python通过内置函数(type())来测试对象的类型,通过(==)运算符判断两个变量指向的对象的值是否相同
  3. Python提供两个对象身份比较运算符,(is)和(is not)来判断两个变量是否指向同一个对象
  4. Python表达式4.5/2的值为(2.25);Python表达式4.5//2的值为(2);Python表达式4.5%2的值为(0.5);Python表达式12/4-2+5*8/4%5/2的值为(1.0)
  5. 计算232-1的python表达式可书写成(math.pow(2,32)-1)
  6. Python中如果语句太长,可以使用(\)作为续航符
  7. Python使用(缩进对齐)格式划分语句块
  8. Python语句分为(简单语句)和复合语句
  9. Python语句print(hex(16))的输出结果是0x10
  10. Python表达式 16-2*5>7*8/2 or "XYZ"!="xyz" and not(10-6>18/2)的值为(True)
  11. Python语句print(2.5.as_integer_ratio())的输出结果是((5,2))
  12. Python语句print(float.as_integer_ratio(1.5))的输出结果是((3,2)
  13. Python语句print(int('20',16),int('101',2))的输出结果是32 5
  14. Python语句print((2-3j).conjugate()*complex(2,3))的输出结果是-5+12J
  15. Python语句print(chr(ord('B')))的结果是(B)
对于Python复习题库,你可以考虑以下几种方法来创建和使用: 1. 使用列表:你可以创建一个包含多个问题和答案的列表,每个问题和答案可以作为一个元组存储在列表中。例如: ```python questions = [("What is Python?", "Python is a high-level programming language."), ("What is a variable?", "A variable is a named location in memory used to store data."), ("How do you define a function in Python?", "You can define a function using the 'def' keyword.")] ``` 然后,你可以使用循环遍历列表并逐个显示问题和答案。 2. 使用字典:你可以创建一个包含问题和答案的字典,其中问题作为键,答案作为值。例如: ```python questions = {"What is Python?": "Python is a high-level programming language.", "What is a variable?": "A variable is a named location in memory used to store data.", "How do you define a function in Python?": "You can define a function using the 'def' keyword."} ``` 然后,你可以使用循环遍历字典并逐个显示问题和答案。 3. 使用类和对象:你可以创建一个Question类,每个Question对象包含一个问题和一个答案。例如: ```python class Question: def __init__(self, question, answer): self.question = question self.answer = answer questions = [Question("What is Python?", "Python is a high-level programming language."), Question("What is a variable?", "A variable is a named location in memory used to store data."), Question("How do you define a function in Python?", "You can define a function using the 'def' keyword.")] ``` 然后,你可以使用循环遍历Question对象列表并逐个显示问题和答案。 这些方法都可以根据你的需求来选择。你可以根据自己的喜好和项目要求来决定使用哪种方法。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值