Datatypes in Python.

Author: neptune | 22nd-May-2022 | Views: 286
#Python

Different types of Datatypes in Python

  • Numbers 

  • Strings

  • Lists 

  • Tuples

  • Dictionary

  • Set

  • Frozenset 

1. Numbers 

Python supports integers, floating-point numbers, and complex numbers. In Python, these numbers are defined as int, float, and complex classes in Python.

When we put a decimal in an Integer then it converts into a Floating-point number. 


Example: 5 is an integer while 5.0 is a floating-point number.

Points to remember :

1. Integer length is not defined it can be of any length.

2. Floating-point is valid till 15th place 16th place is invalid.

Numbers we use daily are of type decimal (Base 10) number system. But other number systems are also present like Binary (Base 2), Hexadecimal (Base 16), and Octal (Base 8).




It's simple to represent these numbers in Python.


Number System

Prefix

Binary

‘0b’ or  ‘0B’

Octal

‘0o’ or ‘0O’

Hexadecimal

‘0x’ or ‘0X’

Example :

Complex numbers are represented in form of (x+yj)  where x is a real part while y is an imaginary part.

That’s all you need to know about numbers in Python.




2. Strings

String is a sequence of Unicode characters.

Points to remember:
1. String can be represented using single quotes ‘Neptune’ or double quotes “Neptune”.

2. Multiline Strings can be represented using tripe quotes.

Examples:

3. Strings are immutable in Python.




3. Lists

List is an ordered sequence of items. It is a widely used datatype in Python.

Points to remember:

1. We can declare a list using [ ] or list class.

2. List index starts from Zero. 

Example :


3. Lists are mutable datatype means we can change the values in the existing list.

Example:

4. List is a heterogeneous datatype which means we can store different types of data in a single list.

Examples :

5. List can also be sliced using [ start index: end index - 1 ].

Examples:




4. Tuples

Tuple is the same as a list it is an ordered sequence of items. But tuple is an immutable data type which means it can’t be modified once created.

1. We can create a tuple using ( ) or tuple class.




2.Tuple is immutable in nature.

3. Tuple values can be accessed using [ ] just like a list.


5. Dictionary

Dictionary is an unordered collection of key-value pairs. It can be defined within braces { key: value } where key and value can be of any data type.

Example:




1. Using the key we can fetch value in constant time O(1).

Example:

2. Different types of keys.

Example:




6. Set

Set is an unordered collection of Unique items. It is defined using { } values separated by comma.

Example:

1. Set is an unordered datatype so there is no index.

Example:


7.FrozenSet

FrozenSet is a modified version of Set. FrozenSet values can’t be changed after creation while we can add or remove values from Set.

Example:

1. We can’t add or remove value from frozenSet.

These all are the data types in python. Hope you got something from this article.

Thanks for Reading !!!





anonymous | May 22, 2022, 10:25 a.m.

Very well explained



Related Blogs
How to extract Speech from Video using Python?
Author: neptune | 29th-Aug-2022 | Views: 2728
#Python
Simple and easy way to convert video into audio then text using Google Speech Recognition API...

How to download video from youtube using python module ?
Author: neptune | 22nd-May-2022 | Views: 1637
#Python
We will let you know how you can easily download the Youtube high quality videos along with subtitle, thumbnail, description using python package..

Mostly asked Python Interview Questions - 2022.
Author: neptune | 25th-May-2022 | Views: 981
#Python #Interview
Python interview questions for freshers. These questions asked in 2022 Python interviews...

How to reverse string in Python ?
Author: neptune | 16th-May-2022 | Views: 796
#Python
We are going to explore different ways to reverse string in Python...

Python Built-in functions lambda, map, filter, reduce.
Author: neptune | 22nd-May-2022 | Views: 793
#Python
We are going to explore in deep some important Python build-in functions lambda, map, filter and reduce with examples...

Python 3.9 new amazing features ?
Author: neptune | 22nd-May-2022 | Views: 788
#Python
We are going to explore the newest features of Python 3.9 really amazing features here list of some features like Dict union, Type hinting etc. with examples...

Best Python package manager and package for virtual environment ?
Author: neptune | 15th-Apr-2022 | Views: 748
#Python #Anaconda #Virtualenv #Pip
Which is the best package manager for python and Virtual environment management using Virtualenv and Anaconda...

Will, AI kills Developer's jobs?
Author: neptune | 22nd-May-2022 | Views: 575
#Python #Machine learning #AI
GPT-3’s performance has convinced that Artificial intelligence is closer or at least AI-generated code is closer than we think. It generates imaginative, insightful, deep, and even excellent content...

Do you know Jupyter is now full-fledged IDE?
Author: neptune | 15th-Apr-2022 | Views: 532
#Python #Jupyter
Jupyter is a widely used tool by Data scientists. So developers from institutions like Two Sigma, Bloomberg and fast.ai convert it into IDE lets see..

Deploy Django project on AWS with Apache2 and mod_wsgi module.
Author: neptune | 22nd-May-2022 | Views: 505
#Python #Django
In this blog I use the AWS Ubuntu 18.22 instance as Hosting platform and used Apache2 server with mod_wsgi for configurations. We create a django sample project then configure server...

What exactly you can do with Python?
Author: neptune | 15th-Apr-2022 | Views: 447
#Python
Well, it's a tricky question to answer because there are lots of application of Python. But, I will tell you about 3 main applications of Python...

Core Python Syllabus for Interviews
Author: neptune | 11th-Jun-2022 | Views: 436
#Python #Interview
STRING MANIPULATION : Introduction to Python String, Accessing Individual Elements, String Operators, String Slices, String Functions and Methods...

Introduction to Apache Spark
Author: neptune | 09th-May-2022 | Views: 265
#Python #Apache Spark
Apache Spark is an open-source, distributed processing system that utilizes in-memory caching and optimized query execution for faster queries...

Classes and Objects in Python 3 | OOP's
Author: neptune | 31st-Aug-2022 | Views: 175
#Python
Object-oriented programming can model real-life scenarios and suit the development of large and complex applications...

TOP 10 PYTHON DEVELOPER SKILLS TO GET HIRED BY FAANG COMPANIES
Author: neptune | 07th-Jul-2022 | Views: 162
#Python
In this article, we will explore top 10 Python skills required to get hired in worlds top most companies. The FAANG companies which are Facebook, Amazon, Apple, Netflix, and Google...

Input and Output in Python
Author: neptune | 15th-Jun-2022 | Views: 154
#Python
In this article, we will see how Python take input from user and How it display the output to user. First we cover input then output...

Inheritance in Python | OOP's
Author: neptune | 05th-Sep-2022 | Views: 74
#Python
Inheritance describes is a kind of relationship between two or more classes, abstracting common details into superclass and storing specific ones in the subclass...

View More