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
    Location
    Europe
    Posts
    125
    Thanks
    0
    Thanked 0 Times in 0 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,312
    Thanks
    0
    Thanked 0 Times in 0 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. #3
    V.I.P voyager1972's Avatar
    Join Date
    Mar 2012
    Location
    derry
    Posts
    667
    Thanks
    0
    Thanked 0 Times in 0 Posts
    print ("Hello " + FirstName +" " + LastName )

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

  5. #5
    Super Moderator saintomer1866's Avatar
    Join Date
    Sep 2005
    Posts
    3,526
    Thanks
    0
    Thanked 0 Times in 0 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.

  6. #6
    V.I.P
    Join Date
    Dec 2004
    Posts
    2,732
    Thanks
    0
    Thanked 3 Times in 1 Post
    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.

  7. #7
    Verified Registered User davorp's Avatar
    Join Date
    Aug 2005
    Location
    Europe
    Posts
    125
    Thanks
    0
    Thanked 0 Times in 0 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
  •