Thursday, May 1, 2008

Variables in Python 2

So, where am I now in my study of python? Ah! in my last post, I assigned numeric values to variables a, b and c. This time, I want to have a variable that contains a string, how am I going to do that?

Try this:

#!/usr/bin/env python
# Filename : stringvar.py
# Description : A simple example that shows how to assign a string to a variable
# Author : Obispo

str="Hello World!"
print "str = ", str

Output:

# ./stringvar.py
str = Hello World!

That's it! The code is so straight forward. Luckily python is not like any other programming language wherein you need to define the data type of your variable first before assigning value into it.


No comments: