Variables and Data Types in Python - Programmrs

  VARIABLES AND DATA TYPES


A variable is a name given to a memory location in a program. Example:

a=20

name="suman"

b=34.34


Data Types in Python


Notes: 

Variable - A container to store the value

Keywords - Reserved words in python

Identifiers - Class/Function/Variable


DATA TYPES

Primarily, there are the following data types in Python.

  • Integers
  • Floating Point Number
  • Strings
  • Booleans
  • None
Python is a fantastic language that automatically identifies the type of data for us.

a=67 (Integer)
b="Python" (String)
c=34.53 (Float)


Rules for Defining the Variable Name
  1. A variable name can contain alphabets, numbers, and underscores.
  2. A variable name can start with an alphabet and underscores
  3. A variable name cannot start with a digit.
  4. No whitespace is allowed to be used inside the variable name.
Examples of a few variable names are:
 Suman, _hari, hello2, etc.


Operators in Python

Operators are symbols used to perform the arithmetic and logical operations between operands.
  1. Arithmetic Operators
  2. Assignment Operators
  3. Comparison Operators
  4. Logical Operators

Type Function and Typecasting

Type function is used to find the data type of the given variable in python. eg.

a=88
The result of type(a) is int.

b="43"
The result of type(b) is string.


Also, An integer can be converted to a string in python and vice-versa.

String (34) - "34"

int("34") - 34

float(34) - 34.0

Here, 34 is a numeric literal, and "34" is a string literal.


INPUT FUNCTION IN PYTHON

input() function

This function allows the user to take input from the keyboard as a string.

a=input("Enter Name")

Note: The output value stored in a is always a string even if the number is entered.

Post a Comment

Previous Post Next Post