从一个句子中只打印出Python中的int,可以通过以下步骤实现:
下面是一个示例代码:
sentence = "This is a sample sentence with 123 and some other words."
# 拆分句子为单词列表
words = sentence.split()
# 遍历单词列表
for word in words:
# 判断单词是否可以转换为整数
if word.isdigit():
# 打印出整数
print(int(word))
这段代码会输出句子中的整数:123
对于这个问题,腾讯云没有特定的产品和链接地址与之相关。
领取专属 10元无门槛券
手把手带您无忧上云