当前位置:首页>python>Python学习必备基础知识100问及答案,Python 精品学习资料收藏下载,高清PDF电子版下载

Python学习必备基础知识100问及答案,Python 精品学习资料收藏下载,高清PDF电子版下载

  • 2026-10-11 05:47:10
Python学习必备基础知识100问及答案,Python 精品学习资料收藏下载,高清PDF电子版下载

由于微信公众号平台的改版,订阅号消息不再是按时间发布顺序展示给用户,没有被星标的账号,粉丝很容易错过推送!如果您想及时收到文章,请一定要将我们设为★星标★账号(如图所示)。

(资料来自网络,Python学习必备基础知识100问及答案PDF电子完整版)

1.三元运算

age = 10
ticket = "儿童票" if age < 12 _______ "成人票"
print(ticket)
A. ? 
B. else:
C. then
D. else

2.输入函数

trafficLight = ______("请输入信号灯颜色 red, green or yellow:")
if trafficLight == "red":
    print("信号灯颜色是:" + trafficLight)
elif trafficLight == "green":
    print("信号灯颜色是:" + trafficLight)
else:
    print("信号灯颜色是:" + trafficLight)
A. user_input
B. input
C. user_enter
D. enter

3.自定义函数返回值

import math
r = float(input("请输入圆的半径:"))
def circleArea():
    ______ math.pi*pow(r, 2)
print("圆的面积是:", circleArea())
A. back 
B. send
C. return
D. param

4.成员运算符

color = {0:"red", 1:"yellow", 2:"green", 3:"white"}
v = color.values()
for c ______ v:
    print(c)
A. in
B. at
C. on
D. by

5.检测字符串是否只由字母组成

name = input("请输入你的英文昵称:") 
isLetter = name.______ 
if isLetter:
    print("有效的昵称!")
else:
    print("无效的昵称!")
A. isCharacter()
B. isChar()
C. isLetter() 
D. isalpha()

6.文件操作

f = ______("tryFile. txt", "w") 
f.write("I am learning Python programming ! ")
f.close
f = ______("tryFile. txt", "r") 
print(f.read())
f.close
A. unwrap
B. unlock
C. untie 
D. open

7.导入模块

# program001.py
def red():
    print("This flower is red")
def yellow():
    print("This flower is yellow")
def green():
    print("This flower is green")

# program002.py
______ program001# 导入模块
program001.red()
program001.yellow()
program001.green()
A. get 
B. import
C. obtain 
D. acquire

8.类参数

class Flower:
    def __init__( ______, name, color ): 
        self.name = name
        self.color = color 
f = Flower("rose", "red")
print("The flower's name is " + f.name)
print("The flower's color is " + f.color)
A. this
B. which
C. self
D. object

9.异常处理

try:
    int("ten")
______ ValueError as message:
    print("Exception occurs ! ", message)
A. except 
B. exception
C. catch
D. finally

10.定义类方法

class Dog: 
    ______ cry(self): 
        print("Dog cries: Wou ! Wou ! ")
class Cat:
    ______ cry(self): 
        print("Cat cries: Meo ! Meo ! ")
d = Dog()
d.cry()
c = Cat()
c.cry()
A. function
B. method
C. define
D. def

(资料来自网络,Python学习必备基础知识100问及答案PDF电子完整版)

(资料来自网络,Python学习必备基础知识100问及答案PDF电子完整版)

点亮在看,你最好看!

最新文章

随机文章