how to create a function in python that prints out uppercase words

  • Last Update :
  • Techknowledgy :

Python String capitalize() method returns a copy of the original string and converts the first character of the string to a capital (uppercase) letter, while making all other characters in the string lowercase letters.,Python String capitalize() Method creates and returns a copy of the original string after modifications.,Return: The capitalize() function returns a string with the first character in the capital.,CS SubjectsMathematicsOperating SystemDBMSComputer NetworksComputer Organization and ArchitectureTheory of ComputationCompiler DesignDigital LogicSoftware Engineering

Output:

Geeks
for geeks

Suggestion : 2

You're pretty close.

for word in s.split():
   if word[0].isupper()

You can also trim this a little from a function into a single list comprehension:

[word
   for word in s.split() if word[0].isupper()
]

If you run this loop on it's own and print the contents, you'll see the results are just characters.

for word in s: print word

# Prints:
   H
e
   ...#(omitting the rest of the characters)

This is easily done by using split() s which splits the string on spaces and returns the list containing the words. Then, you can apply your isupper() call to check for each word in the list.

def print_all_Uppercased(s):
   for word in s.split():
   if word[0].isupper():
   print word

Which now successfully prints:

Hey!
   Hast
Python
Es
Sprachen,

Suggestion : 3

upper() method returns the uppercase string from the given string. It converts all lowercase characters to uppercase.,The upper() method converts all lowercase characters in a string into uppercase characters and returns it.,If no lowercase characters exist, it returns the original string.,Note: If you want to convert to lowercase string, use lower(). You can also use swapcase() to swap between lowercase to uppercase.

Example

message = 'python is fun'

# convert message to uppercase
print(message.upper())

# Output: PYTHON IS FUN

Example

message = 'python is fun'

# convert message to uppercase
print(message.upper())

# Output: PYTHON IS FUN

The syntax of upper() method is:

string.upper()

Example 1: Convert a string to uppercase

# example string
string = "this should be uppercase!"
print(string.upper())

# string with numbers
# all alphabets should be lowercase
string = "Th!s Sh0uLd B3 uPp3rCas3!"
print(string.upper())

Example 2: How upper() is used in a program?

# first string
firstString = "python is awesome!"

# second string
secondString = "PyThOn Is AwEsOmE!"

if (firstString.upper() == secondString.upper()):
   print("The strings are same.")
else:
   print("The strings are not same.")

Suggestion : 4

Remote Work 2022 , Remote Work 2022

The syntax of the method upper() is:

string.upper()

Input:

# Python program to show the working of the upper()
function
visitor007 = 'Flexiple'

print("Original String:")
print(visitor007)

# upper()
function converts string to uppercase
print("\nModified String:")
print(visitor007.upper())

Output:

Original String:
   Flexiple

Modified String:
   FLEXIPLE