簡體   English   中英

if語句中的行繼續符后的意外字符

[英]unexpected character after line continuation character in if statement

這是我從給定字符串中刪除元音的代碼。在if語句條件下,我的代碼在連續行字符后顯示意外字符?有人可以幫忙嗎?

def anti_vowel(text):
r=len(text)
new=[]
for i in range(0,r):
if lower.text[i]!='a' and lower.text[i]!='e'
    and lower.text[i]!='i' and  lower.text[i]!='o' and lower.text[i]!='u':
    new.append(text[i])
print " ".join(new)`

我修改了您的函數以使用集合和列表理解:

def anti_vowel(text):            
    vowels = {'a', 'e', 'i', 'o', 'i'}
    new = [a_letter for a_letter in text if a_letter not in vowels]                    
    return "".join(new)    

print(anti_vowel("Hey You!"))
#prints: Hy Yu!

我只是想以此證明您的工作-那是您的初衷嗎?

text="The brown fox quickly jumped over the lazy dog"
list_of_vow = ['a','e','i','o','u']
new_word = text;

for x in list_of_vow:
    new_word = new_word.replace(x,'')
print(new_word)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM