Skip to main content

Command Palette

Search for a command to run...

Variables

Updated
2 min readView as Markdown
Variables

Variables are containers for storing data values.

Types of Variables:

String Data Types

  • Integer Data Types

  • Floating Data Types

  • Booleans Data Types

String Data Types Variable.

  • String Variable:- Is a series of Characters.

  • A variable name cannot start with the Number.

  • To Create the String Variable we use Double inverted commas - Quotation Marks ("") Or Single inverted commas - Quotation Marks (' ') in Python.

name = "Bro"
print("Hello " + name)
    # OutPut = Hello Bro
  • print(type(age)): This is used to check the Data Type of the Variable
print(type(name)) 
    # OutPut = <class 'str'>

Integer Data Types Variable (Contents Number only)

  • To Create the integer variable we use only contains numbers without any Double inverted commas - Quotation Marks ("") Or Single inverted commas - Quotation Marks (' ')

  • Here in the below example, we use comma separate(,) the two different data types e.g:- STRING Type and INTEGER type.

age = 40
print("My Age is : ", age)
    # OutPut = My Age is:  40
  • Here in the below example, we change the convert Values to str() to avoid the Type Error.
print("My Age is : " + str(age)) 
    # OutPut = My Age is: 40
  • print(type(age)): This is used to check the Data Type of the Variable
print(type(age)) 
    # OutPut = <class 'int'>

Float Data Types Variable.

  • Floating point number (a decimal number Like: 20.5, 856.684 etc)

  • Float, or "floating point number" is a number, positive or negative, containing one or more decimals.

  • Here in the below example, we change the Float Values to str() to avoid the Type Error.

hight = 250.5
print("Your Height is : "+str(height) + " cm")
    # OutPut = Your Hight is: 250.5 cm
  • print(type(age)): This is used to check the Data Type of the Variable
print(type(height))
    # OutPut = <class 'float'>

Booleans Data Types Variable.

  • Booleans represent one of two values: True or False.

  • Booleans also can be used in the Conditions checks and "if statement" where we need to check if the result is True OR False.

human = False
print(human)
    # OutPut = False
  • print(type(age)): This is used to check the Data Type of the Variable
print(type(human))
    # ? OutPut = <class 'bool'>

Learn Python

Part 1 of 2

This Series Helps people to understand the basics of Python for their journey in python Developer Or DevOps.

Up next

Multiple Assignment

Allows us to assign multiple variables at the same time in one line of code.