Variables and Data Types In Python. Topic 6

Variables

Definition: A variable is a name of a container that can store different types of values. We can assign a value to a variable. After assigning a value we can access this value through the variable.

Just imagine, you have a tiffin box. Your mummy fills the box with different types of tiffin. Variable also our tiffin box. We can fill this with different types of data.

In Python programming language, 8 types of variables:

  • i) Integer (int)
    • These variables contain numbers without any decimal point, that is Integer types of variable.
    • Example: a = 25
  • ii) String (str):
    • Represented by a sequence of characters enclosed in single (‘ ‘) or double (” “) quotes.
    • Example: name = “Priti”
  • iii) String (str):
    • Represented by a sequence of characters enclosed in single (‘ ‘) or double (” “) quotes.
    • Example: name = “Priti”
  • Iv) Boolean (bool):
    • Represents either True or False.
    • Example: is_student = True
  • v) List (list):
    • Ordered collection of items.
    • Example: fruits = [‘apple’, ‘banana’, ‘orange’]
  • vi) Tuple (tuple):
    • Similar to lists but immutable (cannot be changed after creation).
    • Example: coordinates = (4, 5)
  • vii) Set (set):
    • Unordered collection of unique items.
    • Example: unique_numbers = {1, 2, 3, 4}
  • viii) Dictionary (dict):
    • Collection of key-value pairs.
    • Example: person = {‘name’: ‘Alice’, ‘age’: 30}

Code In Vscode:

#i) Integer (int)
a = 25

#ii) float(float)
a = 25.02 
b = 2.0

#iii) String (str):
name = "Priti"

#Iv) Boolean (bool):
is_student = True

#v) List:
fruits = ['apple', 'banana', 'orange']

#vi) Tuple:
coordinates = (4, 5)

#vii) Set:
unique_numbers = {1, 2, 3, 4}

#viii) Dictionary (dict):
person = {'name': 'Alice', 'age': 30}

I hope you understand Variables and Data Types In Python. If you do not understand this topic just comment below with your email ID, and I will mail back to you.

Data Types:


# i) Integer (int)
a = 25
print("The type of a is ", type(a))

# ii) float(float)
b = 2.0
print("The type of b is ", type(b))

# iii) String (str):
name = "Priti"
print("The type of name is ", type(name))

# Iv) Boolean (bool):
is_student = True
print("The type of is_student is ", type(is_student))

# v) List:
fruits = ['apple', 'banana', 'orange']
print("The type of fruits is ", type(fruits))

# vi) Tuple:
coordinates = (4, 5)
print("The type of is_student coordinates ", type(coordinates))

# vii) Set:
unique_numbers = {1, 2, 3, 4}
print("The type of unique_numbers is ", type(unique_numbers))

# viii) Dictionary (dict):
person = {'name': 'Alice', 'age': 30}
print("The type of person is ", type(person))

The Output Of This Code Will Be:

Output
The type of a is  <class 'int'>
The type of b is  <class 'float'>
The type of name is  <class 'str'>
The type of is_student is  <class 'bool'>
The type of fruits is  <class 'list'>
The type of is_student coordinates  <class 'tuple'>
The type of unique_numbers is  <class 'set'>       
The type of person is  <class 'dict'>

I hope you understand Variables and Data Types In Python. Topic 6. If you do not understand this topic just comment below with your email ID, and I will mail back to you.

We can also change the data types. Python gives this flexibility. Read more from here.

Finite number of  lines code and infinite possibilities

Programmer, Arpan Bera

Leave a Reply

Your email address will not be published. Required fields are marked *

ABOUT ME
Arpan Bera

Coding is like Love – everyone can start, but only a few finish without errors

Keep Updated to our News and Blog