• Study Materials – Company wise
    • Infosys Archive
    • Accenture Archive
    • AMCAT Archive
    • Capgemini Archive
    • Cisco Archive
    • CoCubes Archive
    • Cognizant(CTS) Archive
    • Dell Archive
    • Deloitte Archive
    • DXC Archive
    • Goldman Sachs Archive
    • Hexaware Technologies Archive
    • LTI Archive
    • MindTree Archive
    • TCS Archive
    • Virtusa Archive
    • Wipro Archive
  • Interview Preparation – E Books
    • C Interview Questions
    • Data Structures Interview Questions
    • DBMS Interview Questions
    • HR Interview Questions
    • Java Interview Questions
    • Operating System Interview Questions
    • Python Interview Questions
    • SQL Query Interview Questions
  • Programming
    • C Programming MCQs
    • C Code Snippets – Output Questions
    • Python Code Snippets – Output Questions
  • Aptitude
    • Verbal Ability for Placements
    • Quant for Placements
  • Register
  • Login
CODE OF GEEKS

We at CODE OF GEEKS, aim at providing best and quality content for our users at no extra cost.

    • Study Materials – Company wise
      • Infosys Archive
      • Accenture Archive
      • AMCAT Archive
      • Capgemini Archive
      • Cisco Archive
      • CoCubes Archive
      • Cognizant(CTS) Archive
      • Dell Archive
      • Deloitte Archive
      • DXC Archive
      • Goldman Sachs Archive
      • Hexaware Technologies Archive
      • LTI Archive
      • MindTree Archive
      • TCS Archive
      • Virtusa Archive
      • Wipro Archive
    • Interview Preparation – E Books
      • C Interview Questions
      • Data Structures Interview Questions
      • DBMS Interview Questions
      • HR Interview Questions
      • Java Interview Questions
      • Operating System Interview Questions
      • Python Interview Questions
      • SQL Query Interview Questions
    • Programming
      • C Programming MCQs
      • C Code Snippets – Output Questions
      • Python Code Snippets – Output Questions
    • Aptitude
      • Verbal Ability for Placements
      • Quant for Placements
    • Register
    • Login
  • [email protected]
  • ..
Login / Register
Apply Now
CODE OF GEEKS
CODE OF GEEKS
  • Study Materials – Company wise
    • Infosys Archive
    • Accenture Archive
    • AMCAT Archive
    • Capgemini Archive
    • Cisco Archive
    • CoCubes Archive
    • Cognizant(CTS) Archive
    • Dell Archive
    • Deloitte Archive
    • DXC Archive
    • Goldman Sachs Archive
    • Hexaware Technologies Archive
    • LTI Archive
    • MindTree Archive
    • TCS Archive
    • Virtusa Archive
    • Wipro Archive
  • Interview Preparation – E Books
    • C Interview Questions
    • Data Structures Interview Questions
    • DBMS Interview Questions
    • HR Interview Questions
    • Java Interview Questions
    • Operating System Interview Questions
    • Python Interview Questions
    • SQL Query Interview Questions
  • Programming
    • C Programming MCQs
    • C Code Snippets – Output Questions
    • Python Code Snippets – Output Questions
  • Aptitude
    • Verbal Ability for Placements
    • Quant for Placements
  • Register
  • Login
0

Cart

Datatypes in Python

  • January 17, 2020
  • CODE OF GEEKS
  • 0


A datatype denotes the type of data required to store in a variable or in a memory space. Datatypes are categorized into two ways :

1. Built-in Datatypes : The datatypes that are already available in Python language are called Built-in types. Built-in datatypes are divided into five categories :

1. None datatype : It denotes that object does not contain any value or is null. It can be used as a default value for parameters inside a function.

2. Numeric datatype : It involves int, float, and complex datatype.

3. Sequence : It involves str for strings, bytes, bytesarray, list, tuple, range.

4. Sets : It involves unordered collection of elements. It includes set and frozen set.

5. Mapping : It represents a group of elements in the form of key-value pairs.

2. User-Defined Datatypes : The datatypes that are defined by users are called user-defined datatypes. Some of the user defined datatypes are : Array, Class etc.

Let us look at them in a gist.

1. int : It represents an integer number. Integer is something without fractional part. For example, 4,55,-456 are all integers.

Storing a integer value to a variable : a = 34

2. float : It represents floating point numbers. For example, 34.67, -56.32 are all floating point numbers.

Storing a floating value to a variable : a = 34.56

Sometimes we also use scientific notations such as E or e, to represent the power of 10. Like, we can write 2.9*10^7 as 2.9E7.

3. complex : It represents a number written in the form of x+yj, where x represents real part and y represents an imaginary part.

Storing a complex value to a variable : a = 4+3j.

4. str : It represents string datatype. A String represents a group of characters. They are generally enclosed in single quotes or double quotes.

Storing a string value to a variable :

s = “Code Of Geeks”

5. bytes : It represents a group of byte numbers. It covers all integers between 0 to 255.

Storing bytes value to a variable :

a = bytes( [23,45,56,45])

6. bytearray : It is similar to bytes datatype. But unlike bytes, bytearray can be modified.

7. list : A List may represent a group of elements. It can store different types of elements and can grow dynamically. In lists, elements are written inside [ ].

Storing list values to a variable :

lst = [3,4,4,2,’Code’]

8. tuple : Tuple is same as list i.e it represents a group of different types of elements but are enclosed in ( ) (parentheses). Tuples can not be modified and hence are read-only lists.

Storing Tuple values to a variable :

tup = (10,20,’Code’)

9. range() : It is a type of sequence datatype that represents the sequence of numbers. Range plays a key role in looping.

To create a range of numbers, we use,

range(5) # prints the numbers from 0 to 4.

Considering other example :

range(2,10,2)

Above statement will produce numbers from 2 to 9 in a step of 2.

Ex : 2,4, 6, 8

10. set : It represents the unordered collection of unique elements. Values in set are enclosed in curly braces { }.

Consider following code :

L = [3,3,5,6,7,7]
s = set(L)
print(s)

Output

{3,5,6,7}

11. Dict : It represents a dictionary. It contains different elements in the form of key-value pairs.

We create an empty list as : d = {}

So these were the different kinds of Python Datatypes. We’ll look at them in detail, in our upcoming lessons.

That’s all, see you in the next lecture.





Tags: builtin datatypesdatatypes in pythonlists pythonpython datatypeswhat are datatypes in python
  • Previous Hello World using C
  • Next Variables & Garbage Collection in Python

Leave a Reply Cancel reply

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

Table of Content – Python

  1. Introduction to Python Programming
    • Python and its features
    • Key Differences : C vs Python
    • Key Differences : Java vs Python
    • Python Flavors
    • PVM and Memory Management in Python

  2. Python Programming Fundamentals
    • 'Hello World' using Python
    • Comments in Python
    • Variables and Garbage Collection in Python
    • Datatypes in Python
    • Determining the Datatype of Literal | type() method
    • Tokens in Python
    • Keywords in Python
    • Identifiers and Naming Convention in Python
    • Literals in Python

  3. Python Operators
    • Operators in Python
    • Python Mathematical Functions

  4. Python User Inputs
    • Taking Inputs | input() function in Python

  5. Python Control Statements
    • Control Statements in Python
    • If-elif-else Statements in Python
    • Looping in Python
    • while loop in Python
    • for loop in Python
    • Infinite loops in Python
    • Nested loops in Python
    • Break Statement in Python
    • Continue Statement in Python
CODE OF GEEKS

Subscribe to Newsletter

CODE OF GEEKS

Learn | Code | Achieve

Reach us

[email protected]
We at CODE OF GEEKS, aim at providing quality content to our users at no cost.
CODE OF GEEKS

Important Pages

About us
Advertise
Privacy Policy
Terms and Conditions

Placements – Study Materials

TCS NQT     Wipro     CapGemini
Accenture     MindTree     CTS
DXC     Hexaware Technologies     AMCAT
CoCubes     Goldman Sachs     Dell
Cisco     Deloitte     Virtusa     LTI     Infosys   

Courses

  • Mail Us
  • Login/Register

Recent Posts

TCS Reasoning 2021
  • October 4, 2021
TCS Verbal 2021
  • October 4, 2021

Copyright 2021 CODE OF GEEKS. All Rights Reserved.

  • →