Day 2 : Datatypes and operators

Hello guys, 
Here we are day 2,
Every language have their own datatypes and different syntax and some advantages. 

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 

1. First letter of an identifier must be alphabet (underscore is also allowed)
2. Identifier can only contain letters, digits, and underscores
3. Identifiers in Python can be of any length
4. White space is not allowed
5. Keywords cannot be used as identifier

(If you know any other programming language then rules are quite same😉) 


What is keyword? 

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

Datatypes mean how much memory does that variable occupies depends on the type of data it is assigned to. So, the data types designate the memory required to store the variable.

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 User
Output




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. Dictionary

A 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


Contact here if you get any problem 
8805271377 WhatsApp

Follow here ❤

@mr._mephisto_ Instagram 

There will be no restrictions just feel free to learn. 

Share and take one more step to share knowledge to others. 

Believe in yourself 🤟 you are awesome. 

Be safe, Be happy😁
Take care of yourself and your family 
Of course watch movies and series🤟😉 
And follow the guidelines of government

Comments

Popular posts from this blog

News website using Flask and news API - Hello World : Part 3

News website using flask and newsapi - Setup Environment : Part 2

Day 9 : Encapsulation and polymorphism