#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    1
    Rep Power
    0

    Smile Python 3.3 Syntax question


    So i am 15 and have decided to learn python. I have found a good tutorial which covers almost everything. I do have some questions that i deem important to know.

    1. When creating this function how does "Fred" become the name since i see no name = "fred"

    Input:
    def print_welcome(name):
    print("welcome", name)

    print_welcome("fred")

    Output:
    welcome fred


    2. I have heard that you should not use white-space in python. Where can i use white-space and where can i not. I do not want to make any bad habits
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    114
    Rep Power
    4
    1. The first (and only) parameter of the function is called "name". When you call the function with the argument "fred", that value is bound to the name "name" in the function's scope. Note, however, that you can explicitly call print_welcome(name="fred") instead, with the same result.

    2. I'm not sure exactly what was meant here. Perhaps what whoever said this was trying to communicate is that whitespace (specifically indentation) is significant in Python.
  4. #3
  5. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,995
    Rep Power
    481
    And since white space significantly denotes blocks of statements, you must post python code in these forums within [code] tags. Please read and follow the link at my signature for more information.
    [code]Code tags[/code] are essential for python code and Makefiles!
  6. #4
  7. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2005
    Posts
    620
    Rep Power
    65
    This might explain the value of a function better:
    Code:
    def print_welcome(name):
        print("A friendly welcome to " + name)
    
    print_welcome("fred")
    print_welcome("amy")
    print_welcome("herbert")
    Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25

IMN logo majestic logo threadwatch logo seochat tools logo