Quantcast
Channel: Basics Category Page - PythonForBeginners.com
Viewing all articles
Browse latest Browse all 193

Variables in Python

$
0
0

What are Variables?

Variables in Python are basically a storage placeholder for texts and numbers. 

The variable has to have a name, so you are able to find it again. 

The name is saved in the memory. You assign a variable with the equal (=) sign. 

After the equal sign comes the value of the variable. 

When you later in your script use the variable , you are referring to the name of the variable and you will get the value of it. 

Variable types

Here is a list of some variable types:

x = 123                                # integer
x = 123L                               # long integer
x = 3.14                               # double float
x = 3+4j                               # complex
x = "hello"                            # string
x = [0,1,2]                            # list
x = (0,1,2)                            # tuple
x = open('hello.py', 'r')              # file

Playing around with variables


length = 1.10
width = 2.20
area = length * width
print "The area is: " , area
Output

>>will print out: The area is:  2.42

The post Variables in Python appeared first on Python For Beginners.


Viewing all articles
Browse latest Browse all 193

Trending Articles