Database Reference
In-Depth Information
Hello World!
“Hello World!” is the most common introduction to any programming or scripting language. The following example
uses three lines of code to demonstrate five important concepts in Python that will be used in nearly every script.
Notice the lack of extraneous text or commands in each line.
>>> myvar = 'Hello World!'
>>> if myvar:
... print(myvar)
...
Hello World!
The first line shows how to assign a value to a variable. The variable does not need to be created before
being assigned a variable. Both steps are done at once. The value assigned to myvar is a string value, making the
variable a string variable.
The second line starts an if block. The block says, “If the variable myvar exists and has a value assigned to it,
proceed to the next line in this block.” The opening line of code blocks always ends with a colon.
The third line prints the value of the myvar variable, followed by a new line. The print function always includes
a newline character at the end of the printed string.
The fourth line requires a carriage return to indicate the code block is finished. This is not the case in a script,
where blank lines after code blocks are not necessary.
The fifth line shows the output of the code-block commands. This would indicate that the myvar variable did
indeed exist and had a value assigned to it, so the line within the code block was executed, evidenced by the success
of the print function.
Finding Help
There is myriad information available on the Internet regarding Python. A simple Internet search will return more
than enough results to refresh one's memory about a forgotten command. But, Python does one better. A full suite of
help is available right from the command line.
Basic syntax on how to use the internal help in Python can be read by calling the help() function, which puts
the user into another command-line interface within Python where almost any keyword (including “help”) found
anywhere in Python can be entered to provide easy-to-understand information:
>>> help()
Welcome to Python 2.6! This is the online help utility.
If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://docs.python.org/tutorial/ .
Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules. To quit this help utility and
return to the interpreter, just type "quit".
To get a list of available modules, keywords, or topics, type "modules",
"keywords", or "topics". Each module also comes with a one-line summary
of what it does; to list the modules whose summaries contain a given word
such as "spam", type "modules spam".
help>
 
Search WWH ::




Custom Search