jags
jags

Reputation: 3

Can you combine different string functions together?

I'm trying to turn a string into lowercase and then count the amount of times a letter appears in that string using Python.

Am I allowed to combine both string functions together? Or is this frowned upon or completely wrong because it does seem to work fine:

name2 = name1.lower().count("a") 

Upvotes: 0

Views: 91

Answers (1)

Matthew Skillman
Matthew Skillman

Reputation: 74

Yes you may chain several calls together in the manner you mentioned. It is both syntactically correct and Pythonic (conforms to normal conventions of using the Python language.)

Upvotes: 2

Related Questions