Insted using
print()
parameter which are limited,use string formatting,from 3.6 we got f-string
.name = input("What's your name: ") print(f'Hello,{name.capitalize()}')
Output:λ python name.py
What's your name: kent
Hello,Kent
As you see f-strings support any Python expressions(eg capitalize()
)inside the curly braces.>>> print(f"Sammy has {4:4} red and {16:16}! blue balloons") Sammy has 4 red and 16! blue balloons >>> for word in 'f-strings are awesome'.split(): ... print(f'{word.upper():~^20}') ~~~~~F-STRINGS~~~~~~ ~~~~~~~~ARE~~~~~~~~~ ~~~~~~AWESOME~~~~~~~