【发布时间】:2019-05-26 16:31:08
【问题描述】:
我正在尝试将字符串文字连接到字符串变量并将该值重新分配给同一个变量。
我试过+= 运算符和类似的东西
string = string + "another string"
但这不起作用。
这是我的代码。
userWord = input("Enter a word: ").upper()
# Prompt the user to enter a word and assign it to the userWord variable
for letter in userWord:
# Loops through userWord and concatenates consonants to wordWithoutVowels and skips vowels
if letter == "A" or letter == "E" or letter == "I" or letter == "O" or letter == "U":
continue
wordWithoutVowels += userWord # NameError: name "wordWithoutVowels" is not defined
print(wordWithoutVowels)
【问题讨论】:
标签: python python-3.x string-concatenation