第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何檢查raw_input == python中的某些內容?

如何檢查raw_input == python中的某些內容?

冉冉說 2021-03-21 15:11:57
這是我寫的,請您看看我的代碼有什么問題。我只是Python的初學者。#!/usr/bin/pythoninput=int(raw_input("Write exit here: "))if input==exit:    print "Exiting!"else:    print "Not exiting!"
查看完整描述

4 回答

?
嗶嗶one

TA貢獻1854條經(jīng)驗 獲得超8個贊

您想測試字符串的相等性"exit",所以不要將其轉換為int


text = raw_input("Write exit here: ")


if text == "exit":

    print "Exiting!"

else:

    print "Not exiting!"

input==exitinput與exit可能使您感到困惑的功能相比。如果您嘗試過,input == Exit它甚至不會運行。


查看完整回答
反對 回復 2021-03-31
?
藍山帝景

TA貢獻1843條經(jīng)驗 獲得超7個贊

Python是一種腳本語言-交互式地運行python(只需鍵入python)或運行調試器(如idle,eric,komodo(等等))非常容易,并且可以使用它。在這里,我嘗試了一些組合,以查看哪些有效,哪些無效:


>>> raw_input("write exit here: ")

write exit here: exit

'exit'

>>> my_input = raw_input("write exit here: ")

write exit here: exit

>>> my_input

'exit'

>>> my_input = int(raw_input("wite exit here: "))

wite exit here: exit


Traceback (most recent call last):

  File "<pyshell#11>", line 1, in <module>

    my_input = int(raw_input("wite exit here: "))

ValueError: invalid literal for int() with base 10: 'exit'


>>> my_input == exit

False

>>> type(exit)

<class 'site.Quitter'>

>>> my_input == "exit"

True

但是,請不要相信我的意思。...打開解釋器,對問題的一小部分進行試驗,您可以立即使用它。


查看完整回答
反對 回復 2021-03-31
  • 4 回答
  • 0 關注
  • 161 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號