Day 2 : Datatypes and operators
What is a Variable?
A variable is actually a memory location reserved to store some value.
In other programming languages like C, C++ variable type must be defined explicitly.
But in Python😎,the values assigned to the variable determines its type. We don’t need the explicit declaration in Python to reserve memory space.
What is identifier?
Basically, identifiers are the unique name given to variables, functions, class and other entities in Python.
There are certain rules that need to be followed while giving a name to any entities in Python.
Rules for writing an identifier in Python
(If you know any other programming language then rules are quite same😉)
Every other programming language, keywords are the reserved words which have predefined meaning and functionality.
Python keywords cannot be used as identifiers (variable names).
Here is the list of keywords in python.
We will use most of keywords👍
Data Types
Python has 5 standard data types.
1. Numbers
2. String
3. List
4. Tuple
5. Dictionary
1. Numbers
In Python, numeric data type represent the data which has numeric value. Numeric value can be integer, floating number or even complex numbers. These values are defined as int, float and complex class in Python.
- Integers – This value is represented by int class. It contains positive or negative whole numbers (without fraction or decimal). In Python there is no limit to how long an integer value can be.
- Float – This value is represented by float class. It is a real number with floating point representation. It is specified by a decimal point. Optionally, the character e or E followed by a positive or negative integer may be appended to specify scientific notation.
- Complex Numbers – Complex number is represented by complex class. It is specified as (real part) + (imaginary part)j. For example – 2+3j
Note – type() function is used to determine the type of data type
2. String
Strings in Python are the sequence of characters stored in contiguous memory location i.e. array of characters. These set of characters are represented in either single quote or double quotes.
Code :
str = "Hi"
print(str) #prints Hi to console
print(str[1]) #prints first character to console
print(str + "User") #concatenates the string with new string UserOutput

3. List
List in Python is an ordered sequence of items separated by a comma(,) and enclosed within square brackets([ ]). Python list is mutable, which means that the value of items can be altered by accessing it using slicing operator [ ].
Example :
4. Tuple
Python tuple is same as Python list, the only difference being that the Python tuples are immutable which mean that the items in Python tuples can be accessed but their value can’t be altered.
Another main difference between tuples and lists besides mutability is that lists are defined inside square brackets [ ], whereas tuples are defined inside parentheses ( ).
5. DictionaryA Python dictionary is an ordered list of key-value pairs. The items in the dictionary are comma separated key-value pairs.
If we have the key, we can retrieve its value anytime, however vice-versa doesn’t work. Hence Python dictionaries are used and optimized for retrieving data.
Dictionaries in Python are defined inside curly braces ‘{ }’ and to access and assign value, slicing operator ‘[ ]’ is used.

Watch this tutorial😁Task
Find and explore each datatype's methods and uses.
Example
List :
The append() method adds an item to the end of the list.
The append() method adds a single item to the end of the list.
The syntax of the append() method is :
 There are many methods just explore them.
Upload screenshot : whatsApp group
Operator :
As operator are very easy to learn and understand so just follow this link
Watch this
If you are interested in reading read this
And subscribe that channel Telusko best indian youtuber
Comments
Post a Comment