Character Set in Python

Python uses the traditional ASCII character set. The latest version (3.2) also recognizes the Unicode character set. The ASCII character set is a subset of the Unicode character set. An ASCII character can be represented as byte (8 bits). Hence a string made out of ASCII characters can be looked upon as a bytestring.

Identifiers

Python is case sensitive. These are rules for creating an indentifier:

Reserved Words

and as assert break
class continue def del
elif else except exec
finally for from global
if import in is
lambda not or pass
print raise return try
while with yield  

Variables

A variable in Python denotes a memory location. In that memory location is the address of where the actual value is stored in memory. Consider this assignment:

 
x = 1 

A memory location is set aside for the variable x. The value 1 is stored in another place in memory. The address of the location where 1 is stored is placed in the memory location denoted by x. Later you can assign another value to x like so:

 
x = 2 

In this case, the value 2 is stored in another memory location and its address is placed in the memory location denoted by x. The memory occupied by the value 1 is reclaimed by the garbage collector.

Unlike other languages like Java that is strongly typed you may assign a different type to value to x like a floating point number.

x = 3.45

In this case, the value of 3.45 is stored in memory and the address of that value is stored in the memory location denoted by x.

Simple Input and Output

You can prompt the user to enter a value by using function input(). This function waits for the user to enter the value and reads what has been typed only after the user has typed the Enter or Return key. The value is then assigned to a variable of your choosing. The input() function reads the keyboard as String. If you want a numerical value instead, wrap the returned String in the eval() function.

x = eval (input ("Enter a number: "))

y = eval (input ("Enter another number: "))

The print () function allows you to print out the value of a variable. If you want to add text to the output, then that text has to be in single or double quotes. The comma (,) is used as the concatentation operator.

print ('x = ', x)
print ("y = ", y)