我是一個Python新手,我問如何讓Python來檢測變量是否以一組字母開頭。像A-L一樣。如何使用Python來檢查字符串的第一個字母是否在一定範圍內?
到目前爲止,我有這樣的:
import time
import os
title = input("Hello! What is your title? (As in Miss Mr etc) ")
name = input("Okay! Now what is your name? ")
sname = input("Okay, now what is your surname? ")
print("Okay, now what is your date of birth?")
dob = input("Type it like this: 26.9.00: ")
email = input("Okay! Please type in your E-mail: ")
phonenum = input("One last thing now! Please type in your phone number: ")
if name in range(A, L):
print("This works!")
else:
print("This doesn't work...")
這不工作,雖然。
'如果name [0] 'ABCDEFGHIJKL':'? '範圍'是整數,它是半開放的(不包括上限),'A'和'L'沒有引號就是標識符,所以沒有理由認爲你應該工作。 – jonrsharpe
請編輯標題,以便作爲英語問題使用。 –