Python Values, Variables and Types

Values and types:

A value is one of the most basic things in any program works with. A value may be characters i.e. ‘Hello, World!’ or a number like 1,2.2 ,3.5 etc.Values belong to different types: 1 is an integer, 2 is a float and ‘Hello, World!’ is a string etc.

First, we type the python command to start the interpreter.

Numbers:

Python supports 3 types of numbers: integers, float and complex number. If you want to know  what type a value has you can use type() function. Paste the following code and click the run button to check the output.

print(type(1))
print(type(2.2))
print(type(complex(2,3)))

Try it Yourself

Strings:

Strings are defined either with a single quote or a double quotes. The difference between the two is that using double quotes makes it easy to include apostrophes.

print(type('Hello World'))
print(type("Today's News Paper"))

Try it Yourself

Variables:

A variable is nothing but a name that refers to a value. An assignment statement creates new variables and gives them values.

name="Mr. XYZ"
id=123
height=165.5

print(name)
print(id)
print(height)

The type of a variable means the type of the value it refers to.

print(type(name))
print(type(id))
print(type(height))

You can do assignments on more than one variable “simultaneously” on the same line like the following code.

a, b, c = "Make", "Me", "Analyst"
d=a+b+c
print(d)

Try it Yourself

Installing Python in Windows

Variable Names and Keywords