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
- A variable name can contain alphabets, numbers, and underscores.
- A variable name can start with an alphabet and underscores
- A variable name cannot start with a digit.
- 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.
- Arithmetic Operators
- Assignment Operators
- Comparison Operators
- 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.