Python Forum
learning python and need help with an output.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
learning python and need help with an output.
#1
I'm very new, and am trying to remove a space in the output of my program. (Sorry if this is stupidly easy to do, i'm very, very new to python.)

a = input()
print('Hello,', a, '!')
Reply
#2
Do you mean print('Hello, ', a, '!', sep='') ?
Reply
#3
that worked! Thanks!
Reply
#4
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~~~~~~~
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020