0

I'm doing homework, and I need to have my list append its variable elements so the first character is capitalized. Instead it's capitalizing all the characters in the elements.

fangs = ['facebook','apple','netflix','google'] 
upper_fang = []

for fang in fangs:
    upper_fang.append(fang.upper())

print(upper_fang)

#['FACEBOOK', 'APPLE', 'NETFLIX', 'GOOGLE']

The above sequence are my actual results, but I want this:

['Facebook','Apple','Netflix','Google']
drec4s
  • 7,946
  • 8
  • 33
  • 54

1 Answers1

0

You're looking for capitalize:

fangs = ['facebook','apple','netflix','google'] 
upper_fang = [] 
for fang in fangs: 
    upper_fang.append(fang.capitalize()) 

print(upper_fang)

Output:

['Facebook', 'Apple', 'Netflix', 'Google']

Alternatively, you can use a list comprehension:

[company.capitalize() for company in fangs]
gmds
  • 19,325
  • 4
  • 32
  • 58