Thursday, February 9, 2017

Variables

In last lesson we've introduced values and type and now it's time to store them someware. Variables are one of the most powerful features of a programming language. A variable is a name that refers to a value.
Asignment statement creates new variables and gives them values. Using a variable you can store all types of values such as strings (str), integers(int) , float ...
message = 'Hello, it's me!'
n = 121
pi = 3.141592   
With previous asignment statemets we've assigned string to a new variable called message, the integer 121 is asigned to variable n and with third asigned approximate value of pi to variable named pi.
Using print statemets you can display a value of variable. For example:
print message
Hello, it's me!
print n
121
print pi
3.141592
Type statement can be used to see what the type of a variable is the type of the value it refers to.

type(message)
type(n)
type(pi)

No comments:

Post a Comment