Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 22nd, 2012, 05:26 PM
calderhutchins calderhutchins is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 1 calderhutchins User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 25 sec
Reputation 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

Reply With Quote
  #2  
Old December 22nd, 2012, 06:36 PM
Nyktos Nyktos is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 76 Nyktos User rank is Corporal (100 - 500 Reputation Level)Nyktos User rank is Corporal (100 - 500 Reputation Level)Nyktos User rank is Corporal (100 - 500 Reputation Level)Nyktos User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 3 h 26 m 18 sec
Reputation Power: 2
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.

Reply With Quote
  #3  
Old December 22nd, 2012, 08:25 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is online now
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,390 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 14 h 48 m 54 sec
Reputation Power: 383
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!

Reply With Quote
  #4  
Old December 22nd, 2012, 09:55 PM
Dietrich's Avatar
Dietrich Dietrich is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 484 Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 23 h 21 m 50 sec
Reputation Power: 63
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Python 3.3 Syntax question

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap