Results 1 to 7 of 7

Thread: How to create space when printing two variables?

  1. #1
    Verified Registered User davorp's Avatar
    Join Date
    Aug 2005
    Posts
    125
    Thanks
    60
    Thanked 48 Times in 30 Posts

    How to create space when printing two variables?

    This is maybe a basic question, but it has been giving me a headache. How to I make space when printing two variables.

    Example:

    Code:
    FirstName = input("What's your first name?  ")
    
    LastName = input("What's your last name?  ")
    print ("Hello: )",  FirstName  + LastName)

  2. #2
    V.I.P
    Join Date
    Jul 2006
    Posts
    1,276
    Thanks
    638
    Thanked 1,422 Times in 657 Posts
    you can read here

    Code:
    https://stackoverflow.com/questions/9969684/how-do-i-add-space-between-two-variables-after-a-print-in-python

  3. The Following User Says Thank You to ozzsurf For This Useful Post:

    davorp (08-04-2018)

  4. #3
    V.I.P voyager1972's Avatar
    Join Date
    Mar 2012
    Posts
    657
    Thanks
    423
    Thanked 530 Times in 267 Posts
    print ("Hello " + FirstName +" " + LastName )

  5. The Following User Says Thank You to voyager1972 For This Useful Post:

    davorp (08-04-2018)

  6. #4
    Verified Registered User davorp's Avatar
    Join Date
    Aug 2005
    Posts
    125
    Thanks
    60
    Thanked 48 Times in 30 Posts
    I have tried that, but reports an error, unexpected syntax “ “ .

  7. #5
    Super Moderator saintomer1866's Avatar
    Join Date
    Sep 2005
    Posts
    3,516
    Thanks
    4,440
    Thanked 7,747 Times in 2,327 Posts
    it may depend on which version of python you are using
    but try this;

    firstName = raw_input("What's your first name? ")
    lastName = raw_input("What's your last name? ")
    print "Hi there, " + firstName + " " + lastName + "!"

    St.O
    Last edited by saintomer1866; 07-04-2018 at 09:13 PM.

  8. The Following User Says Thank You to saintomer1866 For This Useful Post:

    davorp (08-04-2018)

  9. #6
    V.I.P
    Join Date
    Dec 2004
    Posts
    2,809
    Thanks
    1,305
    Thanked 4,802 Times in 1,938 Posts
    str1 = "Firstname"
    str2 = " "
    str3 = "Lastname"
    fullname = str1 + str2 + str3
    print fullname


    Something like that should work.


    Also look at your last line: print ("Hello: )", FirstName + LastName)

    You have got a bracket inside your brackets ()) - you aren't closing the brackets like that, should be like this (()) - do you know what I mean?

    Also it should be more like this:

    string = "Hello " + FirstName + " " + LastName
    print string
    Last edited by mrdude; 08-04-2018 at 12:58 AM.

  10. The Following User Says Thank You to mrdude For This Useful Post:

    davorp (08-04-2018)

  11. #7
    Verified Registered User davorp's Avatar
    Join Date
    Aug 2005
    Posts
    125
    Thanks
    60
    Thanked 48 Times in 30 Posts
    Thanks everyone.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •