Helpful Information
 
 
Category: Development Articles
Python 101 (part 2): If Wishes Were Pythons

I WANT MORE : things like executing commands from the script

Careful, the text talks (in an aside) about the print() function. This is _wrong_, there is a print _statement_, but no print() function.

Once more, a slight confusion over statements and expressions leads me to point out that, although the article says, "Well, comparison operators come in very useful when building conditional expressions - and conditional expressions come in very useful when adding control routines to your code," Python does not have conditional expressions, only conditional staements.

In this, Python is unlike Perl or C. Pythonistas claim this makes the resulting code more readable.

Very good tutorial. Just a comment on:

> Since Python does not support PHP-or
> JSP-style "switch/case" conditional
> statements, the "if-elif-else" construct
> is the only way to route program
> control to multiple code blocks.

Python provide simple enough function pointers to implement switch/case in a
more elegant way than a long if/else.
But maybe this is advanced code:

def work():
print "Ahiho"

def fun():
print "Yuk"

>>> tasks = {'monday':work,'tuesday':work,'sunday':fun}
>>> tasks['monday']()
AhiHo

Why doesn't python allow wrapping around of text when there is an if block indented. It gives an error.

whitespace is significant. try the line continuation \

Thank you for the inro to Python.
I enjoyed it. Please keep these type
of tutorials coming.

Abe Almonte

InktomiSearch uses python as its scripting language. I've been trying to hack that up a bit but not being familiar wtih python, I was breaking stuff constantly. This series is a great quick intro to the language. Much appreciated!

Python is like one of those languages that you don't hear of until you get deep into Geekdom. I've been working in the IT industry for a long time, and I've never actually seen it being used. Is this like a cult language (The Black Sabbath of 'puter languages)??

Vikram,

Presumably the semicolon at the end of:-

else:
print ("Finally! A user with active brain cells!");

is a mistake?

So,

>>> str='hobgoblin'
>>> str[:7]
'hobgobl'

Since str[0] is 'h', either the second value of the slice is a counter or the slice means from the first value up to [but not including] the second.

>>> str[3:3]
''
>>> str[3:4]
'g'

Ok, so the slice is:-
[from:to but not including]

Not a problem, but it's certainly different from what I expected.

Python 101 \(part 2\): If Wishes Were Pythons (http://www.devshed.com/c/a/Python/Python-101-part-2-If-Wishes-Were-Pythons)

Begin your tour of Python with a look at its number and string types, together with examples of how they can be used in simple Python programs. Along the way, you'll also learn how to build conditional expressions, slice and dice strings, and accept user input from the command line.

Please discuss this article in this thread. You can read the article here (http://www.devshed.com/c/a/Python/Python-101-part-2-If-Wishes-Were-Pythons).










privacy (GDPR)