Skip to content
Home » Python Data Types | Python Tutorial #5

Python Data Types | Python Tutorial #5

Python Tutorial #5

Hey Programmers, In this Tutorial of Python Course We will Learn About Python Data Types, What are the Different Data Types, Where is Use Them And How to Use Them So let’s But Before Starting If You Have Not Read the Previous Parts of this Course Do Access Them Here:- Python Course For Beginners

Table of Contents:

  • What are Data Types In Python?
  • Numeric
  • Sequence Type
  • Boolean
  • Set
  • Dictionary

In Python, Data Types are used to Categorize the Data Items. It Tells us the Type Of Value Stored In a Item. It represents a value type that indicates what operations can be performed on a particular piece of data. data types are actually classes and variables are objects of those classes.

There are Currently 5 Data Types In Python:

  • Numeric
  • Sequence Type
  • Boolean
  • Set
  • Dictionary

Numeric Data Type

Numeric Data Type Represents the Data which has a Numeric Value, it can either be integer, floating number, or even it can be a complex number. The Numeric Values are Defined as the Following: int, float, and complex etc.

  • Integers: In Python, an integer is a zero, positive or negative integer with no fractional part and unlimited precision. The following are valid integer characters in Python. Integers can be binary, octal, and hexadecimal values. All integer or variable characters are objects of class int.
  • Float: The float type in Python represents a floating point number. Float is used to represent real numbers and is written with a decimal point that divides the integer part and the decimal part.
  • Complex Numbers: A complex number is created from real numbers. Python complex numbers can be generated using the direct assignment statement or using the complex() function. Complex numbers are used mainly when we use two real numbers.

Examples:

# Integers Data Type
x = 20
print(type(x))

# Float Data Type
y = 9.2
print(type(y))

# Complex Numbers
z = 6 + 4j
print(type(z))

Output:

<class 'int'>
<class 'float'>
<class 'complex'>

Run Code

Sequence Type

In Python, sequence is the general term for an ordered set. There are several types of sequences in Python, the latter three being the most important. Lists are the most flexible string type. List items can be any object, and the list is editable – they can be changed.

There are 3 Types of Sequence In Python:

  • String
  • List
  • Tuple

Strings In Python

Strings in Python are byte arrays representing unicode characters. However, Python has no character data type, a single character is simply a string of length 1. Square brackets can be used to access string elements.

Creating Strings In Python:

Strings In Python are Created By using Single or Double Quotes and Sometimes In Triple Quotes Also.

# Strings In Python
# Strings Using Single Quotes
Programmer = 'Mr Programmer is Best'
print("String made using Single Quotes:", Programmer)

# Strings In Python
# Strings Using Double Quotes
Programmer = "Mr Programmer is Great"
print("String made using Double Quotes:", Programmer)

# Strings In Python
# Strings Using Triple Quotes
Programmer = '''Mr Programmer is Awesome'''
print("String made using Triple Quotes:", Programmer)

# Strings In Python
# Multi-line String Using Triple Quotes

Python3 = '''Python was
             launched in
             1991'''
print("This is a Multi-line String:" Python3)

Output:

String made using Single Quotes: Mr Programmer is Best
String made using Double Quotes: Mr Programmer is Great
String made using Triple Quotes: Mr Programmer is Awesome
Python was
             launched in
             1991

Run Code

Lists In Python

Lists are used to save more than one objects in a variable.

Creating Lists In Python:

We can create lists in Python By Using the Square Brackets ‘[ ]’ .

# Lists In Python
# Use the Square Bracket to Create Lists In Python
my_list = ["This is a List In Python"]
print(my_list)

# Creating Lists With Strings 
# Use String to Create Lists In Python
Mr Programmer  = ['The Real Name of Mr Programmer is Tanmay']

# Creating Lists with Multiple Values
items = ['apple', 'banana', 'mango']
print(items)

Tuples In Python

Tuples In Python Are Used to Store Multiple Items In a Single Variable. Tuples are Unchangeable & Ordered.

Creating Tuples In Python:

We can Create Tuples By Using Small Brackets ‘( )

# Creating Tuples In Python
# Tuples 

my_tuple = ('Tanmay', 'Programmer')
print(my_tuple)

# Creating Tuples With Tuple Function In Python
# Tuples 

my_tuple = tuple('Mr Programmer') 
print("Tuple Function In Python") 
print(my_tuple) 

Output:

('Tanmay', 'Programmer')
Tuple Function In Python
('M', 'r', ' ', 'P', 'r', 'o', 'g', 'r', 'a', 'm', 'm', 'e', 'r')

Run Code

Booleans In Python

Booleans are the Type of Data Type Which Displays the Output In Either True or False, If the Condition is Correct then it will print true else the condition is wrong false.

Example:

# Booleans In Python
# Getting the Type of Data Type (Boolean)
print(type(True))
print(type(False))
  
print(type(true))

Output:

<class 'bool'>
<class 'bool'>

Traceback (most recent call last):
  File "/home/jdoodle.py", line 6, in <module>
    print(type(true))
NameError: name 'true' is not defined

Sets In Python

Sets is used to store multiple items in a single variable. Set is one of Python’s 4 built-in data types used to store collections of data, the other 3 being List, Tuple, and Dictionary, all of which have different qualities and uses. A set is an unordered, immutable* and non-indexed set.

Creating Sets:

We can create sets using the set() function in python, or by using curly braces separated by ‘comma’.

my_set = set("Python is a High Level Programming Language")
print(my_set)

Output:

Initial set: 
{'Python is a High Level Programming Language'}

Dictionary In Python

A dictionary in Python is an unordered collection of data values, used to store data values ​​like a map, unlike other data types that contain only a single value. As an element, the dictionary contains a key: value pair. Key values ​​are provided in the dictionary for more optimization. Each key-value pair in the dictionary is separated by a colon :, while each key is separated by a “comma”.

Creating Dictionary In Python:

my_dict =  {1: 'Mr Programmer', 2: 'Is', 3: 'Best'} 
print("\nDictionary with the use of Integer Keys: ") 
print(my_dict) 

Output:


Dictionary with the use of Integer Keys: 
{1: 'Mr Programmer', 2: 'Is', 3: 'Best'}

Run Code

Python Courses [PARTS]:

Leave a Reply

Your email address will not be published. Required fields are marked *

You cannot copy content of this page

Top 10 Programming Languages to Learn In 2023! 9 Best Extensions For Web Developers! | Chrome Extensions For Web Developers Web Development Roadmap Best Resources to Learn PYTHON FREE! Web Vs App Development- Which one is Better?