GIDForums  

Go Back   GIDForums > Computer Programming Forums > Python Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 30-Jul-2005, 22:27
crystalattice's Avatar
crystalattice crystalattice is offline
Flame War Instigator
 
Join Date: Apr 2004
Location: San Diego
Posts: 1,543
crystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nice
Post

Re: Beginning Python Tutorial (Part 2)


I just posted a GID Community blog entitled: Beginning Python Tutorial (Part 2).

Quote:
Last time I covered the basics of running Python programs. Today I'll talk about the types and operators used in Python, as well as the syntax Python uses.

Python is based on the C programming language and is written in C, so much of the format Python uses will be familiar to C and C programmers. However, it makes life a little easier because it's not made to be a low-level language (it's difficult to interact heavily with hardware or perform memory allocation) and it has built-in "garbage collection" (it tracks references to objects and automatically removes objects from memory when they are no longer referenced), which allows the programmer to worry more about how the program will work rather than dealing with the computer. read more...

Please let me know what you think.

This is an auto-generated message posted by GIDNetwork™ on behalf of the author.
__________________
Common Sense v2.0-Striving to make the world a little bit smarter.
  #2  
Old 31-Jul-2005, 10:07
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough

Block comments?


Again, a really interesting article. Thank you.

I was wondering, what about block / multiline comments? Does it exist for Python? Comments start with #, right? In the article, you mentioned "asterisk", was that a typo?

And I am not quite clear about the indentation bit under Python Syntax. I think it would help me understand if you can supply a if/else example below in a reply. What about else ifs?
  #3  
Old 31-Jul-2005, 12:25
crystalattice's Avatar
crystalattice crystalattice is offline
Flame War Instigator
 
Join Date: Apr 2004
Location: San Diego
Posts: 1,543
crystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nice
Quote:
Originally Posted by JdS
Again, a really interesting article. Thank you.

I was wondering, what about block / multiline comments? Does it exist for Python? Comments start with #, right? In the article, you mentioned "asterisk", was that a typo?

And I am not quite clear about the indentation bit under Python Syntax. I think it would help me understand if you can supply a if/else example below in a reply. What about else ifs?
Yes, I made a boo-boo. It is indeed the "pound sign" or "hash mark" that is used to make comments, not the asterisk. (I was looking at the number 8 key while typing ). And I haven't read anything so far that says Python does multi-line comments. I'm guessing that you just add a hash prior to every line of comment.

Here's an if statement borrowed from the Python.org tutorial:
Code:
>>> x = int(raw_input("Please enter an integer: ")) >>> if x < 0: ... x = 0 ... print 'Negative changed to zero' ... elif x == 0: ... print 'Zero' ... elif x == 1: ... print 'Single' ... else: ... print 'More' ...
I should mention that I was wrong when I said the "..." don't appear in the Python interactive prompt. It does appear when writing indented code blocks, such as if statements. However other times it doesn't appear, so don't sweat it too much.

I was going to cover "else if" when I talk about control loops, but as you can see, "else if" is shortened to "elif". You can use a final "else" at the end of the code block, if needed.

The amount of indentation doesn't matter, only how the indentation relates to other indented statements. The easiest way to explain it is with the "if, else" statement.
CPP / C++ / C Code:
/*  Warning:  bogus C code!  */

if (some condition)
        if (another condition)
                do_something(fancy);
else
        this_sucks(badluck);
In C/C++, this would be not do what the programmer intended, since C/C++ "else" statements only relate to the closest "if". However, since indentation is significant, the intention of the writer is clear: the "else" statement applies to the first "if" and not the closest one.

If this doesn't clear things up, please let me know.
__________________
Common Sense v2.0-Striving to make the world a little bit smarter.
 
 

Recent GIDBlogMeeting the local Iraqis by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Erco video tutorial problem cohadar FLTK Forum 2 13-Aug-2005 10:07
Re: Beginning Python Tutorial (Part 1) crystalattice Python Forum 5 01-Aug-2005 17:14
[Tutorial] Pointers in C (Part II) Stack Overflow C Programming Language 0 27-Apr-2005 17:36
[Tutorial] Pointers in C (Part I) Stack Overflow C Programming Language 1 08-Apr-2005 18:35

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 05:04.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.