Hacker blog

Python Beginner

View Home

Python Variables

Variables are containers where the datas can be stored. Variables declaration in Python doesn’t require any particular type, and can even after they have been set.The equal sign (=) is used to assign a value to a variable.

Basic Data Types in Python

Python 3.9.2 (default, Feb 28 2021, 17:03:44)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> width = 20
>>> width

Rules for Python variables:

Declarations of variables using types:

w = 1+2j      # w will be (1+2j)
x = str(3)    # x will be '3'
y = int(3)    # y will be 3
z = float(3)  # z will be 3.0

>>> a = True
>>> w = 1+2j
>>> x = 5
>>> y = "John"
>>> z = 6.6
>>> type(v)
<class 'bool'>
>>> type(w)
<class 'complex'>
>>> type(x)
<class 'int'>
>>> type(y)
<class 'str'>
>>> type(z)
<class 'float'>
>>>

Variables

Top

Back