确切地说,在字符串上方有四个以大写字母开头的单词。这是德里,城市和印度。
为此,应使用两个字符串函数。假设字符串中的单词由单个空格字符分隔,split()函数将给出单词列表。
其次,要检查每个单词的首字符是否大写,请使用isupper()函数。
以下代码列出了以大写字母开头的单词。
s1="This is not true that Delhi is the hottest or coldest City in India" for word in s1.split(): if word[0].isupper(): print (word)
输出为:
This Delhi City India