SlideShare une entreprise Scribd logo
1  sur  25
BASIC DATA TYPES IN PYTHON
PROF. SUNIL D. CHUTE
HEAD DEPT OF COMPUTER SCIENC
M.G. COLLEGE ARMORI
BASIC DATA TYPES IN PYTHON
 Data types are the classification or
categorization of data items. It represents the
kind of value that tells what operations can
be performed on a particular data. Since
everything is an object in Python
programming, data types are actually classes
and variables are instance (object) of these
classes.
One way to categorize these basic data types is in
one of four groups:
 Numeric: int, float and the less frequently
encountered complex
 Sequence: str (string), list and tuple
 Boolean: (True or False)
 Dictionary: dict(dictionary) data type, consisting
of (key, value) pairs
NOTE: It's important to point out that Python usually doesn't require you
to specify what data type you are using and will assign a data type to
your variable based on what it thinks you meant.
An equally important thing to point out is that Python is a
"loosely/weakly typed" programming language, meaning that a variable
can change its type over the course of the program's execution, which
isn't the case with "strongly typed" programming languages (such as
Java or C++).
NUMERIC DATA TYPES
These data types are fairly straight-forward and represent
numeric values. These can be decimal values, floating point
values or even complex numbers.
 Integer Data Type - int
The int data type deals with integers values. This means
values like 0, 1, -2 and -15, and not numbers like 0.5, 1.01, -
10.8, etc.
If you give Python the following code, it will conclude that a is
an integer and will assign the int data type to it:
>>> x = 5
>>> type(x)
<class 'int'>
We could have been more specific and said something along these
lines, to make sure Python understood our 5 as an integer, though,
it'll automatically do this exact same thing under the hood:
>>> x = int(5)
>>> type(x)
<class 'int‘>
It's worth noting that Python treats any sequence of numbers (without a
prefix) as a decimal number. This sequence, in fact, isn't constrained.
That is to say, unlike in some other languages like Java, the value of
the int doesn't have a maximum value - it's unbounded.
The sys.maxsize may sound counterintuitive then, since it implies that that's
the maximum value of an integer, though, it isn't.
>>> x = sys.maxsize
>>> x
2147483647
This appears to be a 32-bit signed binary integer value, though, let's see
what happens if we assign a higher number to x:
>>> x = sys.maxsize
>>> x+1
2147483648
In fact, we can even go as far as:
>>> y = sys.maxsize + sys.maxsize
>>> y
4294967294
The only real limit to how big an integer can be is the memory
of the machine you're running Python on.
 Prefixing Integers
What happens when you'd like to pack a numeric value in a
different form? You can prefix a sequence of numbers and tell
Python to treat them in a different system.
More specifically, the prefixes:
 0b or 0B - Will turn your integer into Binary
 0o or 0O - Will turn your integer into Octal
 0x or 0X - Will turn your integer into Hexadecimal
 # Decimal value of 5
>>> x = 5
>>> x
5
 # Binary value of 1
>>> x = 0b001
>>> x
1
 # Octal value of 5
>>> x = 0o5
>>> x
5
 # Hexadecimal value of 10
>>> x = 0x10
>>> x
16
FLOATING POINT DATA TYPE - FLOAT
 The float type in Python designates a floating-point number. float values
are specified with a decimal point. Optionally, the
character e or E followed by a positive or negative integer may be
appended to specify scientific notation
Ex.1 >>> 4.2 4.2
>>> type(4.2)
<class 'float'>
Ex.2 >>> 4.
4.0
Ex.3 >>> .2
0.2
Ex.4>>> .4e7 4000000.0
>>> type(.4e7)
<class 'float'>
Ex.5>>> 4.2e-4
COMPLEX NUMBERS
 Complex numbers are specified as <real
part>+<imaginary part>j.
Ex. >>> 2+3j
(2+3j)
>>> type(2+3j)
<class 'complex'>
STRINGS
 Strings are sequences of character data. The string
type in Python is called str.
 String literals may be delimited using either single or
double quotes. All the characters between the opening
delimiter and matching closing delimiter are part of the
string:
Ex.>>> print("I am a string.")
I am a string.
>>> type("I am a string.")
<class 'str'>
Ex.>>> print('I am too.')
I am too.
>>> type('I am too.')
<class 'str'>
 A string in Python can contain as many characters as you
wish. The only limit is your machine’s memory resources.
A string can also be empty:
Ex. >>> ''
''
 What if you want to include a quote character as part of
the string itself? Your first impulse might be to try
something like this:
Ex.>>> print('This string contains a single quote (')
character.')
SyntaxError: invalid syntax
Ex. >>> mystring = "This is not my first String"
>>> print (mystring);
This is not my first String
 to join two or more strings.
Ex.>>> print ("Hello" + "World");
HelloWorld
Ex. >>> s1 = "Name Python "
>>> s2 = "had been adapted "
>>> s3 = "from Monty Python"
>>> print (s1 + s2 + s3)
Name Python had been adapted from Monty
Python
 use input() function
Ex.>>> n = input("Number of times you
want the text to repeat: ")
Number of times you want the text to
repeat:
>>> print ("Text"*n);
TextTextTextTextText
 Check existence of a character or a sub-
string in a string
Ex.>>> "won" in "India won the match"
True
PYTHON LIST DATA TYPE
 List is an ordered sequence of items. It is one of
the most used datatype in Python and is very
flexible. All the items in a list do not need to be
of the same type.
 Declaring a list is pretty straight forward. Items
separated by commas are enclosed within
brackets [ ].
Ex. a = [1, 2.2, 'python']
We can use the slicing operator [ ] to extract an
item or a range of items from a list. The index
starts from 0 in Python.
PYTHON TUPLE DATA TYPE
 Tuple is an ordered sequence of items same
as a list. The only difference is that tuples are
immutable. Tuples once created cannot be
modified.
 Tuples are used to write-protect data and are
usually faster than lists as they cannot
change dynamically.
 It is defined within parentheses () where
items are separated by commas.
Ex. t = (5,'program', 1+3j)
 We can use the slicing operator [] to extract
items but we cannot change its value.
PYTHON SET DATA TYPE
 Set is an unordered collection of unique
items. Set is defined by values separated by
comma inside braces { }. Items in a set are
not ordered.
 A set is created by placing all the items
(elements) inside curly braces {}, separated
by comma, or by using the built-
in set() function.
 It can have any number of items and they
may be of different types (integer, float, tuple,
string etc.). But a set cannot have mutable
PYTHON DICTIONARY DATA TYPE
 Python dictionary is an unordered collection
of items. Each item of a dictionary has
a key/value pair.
 It is generally used when we have a huge
amount of data. Dictionaries are optimized
for retrieving data. We must know the key to
retrieve the value.
 In Python, dictionaries are defined within
braces {} with each item being a pair in the
form key:value. Key and value can be of any
type.
CONVERSION BETWEEN DATA TYPES
Basic data types in python

Contenu connexe

Tendances (20)

Arrays in c
Arrays in cArrays in c
Arrays in c
 
Chapter 07 inheritance
Chapter 07 inheritanceChapter 07 inheritance
Chapter 07 inheritance
 
Lesson 03 python statement, indentation and comments
Lesson 03   python statement, indentation and commentsLesson 03   python statement, indentation and comments
Lesson 03 python statement, indentation and comments
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in python
 
python Function
python Function python Function
python Function
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
 
Array in c++
Array in c++Array in c++
Array in c++
 
An introduction to Python for absolute beginners
An introduction to Python for absolute beginnersAn introduction to Python for absolute beginners
An introduction to Python for absolute beginners
 
Python programming : Strings
Python programming : StringsPython programming : Strings
Python programming : Strings
 
Python functions
Python functionsPython functions
Python functions
 
Python Data-Types
Python Data-TypesPython Data-Types
Python Data-Types
 
Python basics
Python basicsPython basics
Python basics
 
Data handling CBSE PYTHON CLASS 11
Data handling CBSE PYTHON CLASS 11Data handling CBSE PYTHON CLASS 11
Data handling CBSE PYTHON CLASS 11
 
Tuple in python
Tuple in pythonTuple in python
Tuple in python
 
CLASS OBJECT AND INHERITANCE IN PYTHON
CLASS OBJECT AND INHERITANCE IN PYTHONCLASS OBJECT AND INHERITANCE IN PYTHON
CLASS OBJECT AND INHERITANCE IN PYTHON
 
Python-01| Fundamentals
Python-01| FundamentalsPython-01| Fundamentals
Python-01| Fundamentals
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of Constructors
 
Tuple in python
Tuple in pythonTuple in python
Tuple in python
 
Data structures
Data structuresData structures
Data structures
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
 

Similaire à Basic data types in python

Similaire à Basic data types in python (20)

Python cheat-sheet
Python cheat-sheetPython cheat-sheet
Python cheat-sheet
 
Presentation on python data type
Presentation on python data typePresentation on python data type
Presentation on python data type
 
Python 3.pptx
Python 3.pptxPython 3.pptx
Python 3.pptx
 
python
pythonpython
python
 
Python slide.1
Python slide.1Python slide.1
Python slide.1
 
Python PPT2
Python PPT2Python PPT2
Python PPT2
 
unit 1.docx
unit 1.docxunit 1.docx
unit 1.docx
 
Introduction to Basics of Python
Introduction to Basics of PythonIntroduction to Basics of Python
Introduction to Basics of Python
 
Python basics
Python basicsPython basics
Python basics
 
Python Session - 3
Python Session - 3Python Session - 3
Python Session - 3
 
Python quick guide
Python quick guidePython quick guide
Python quick guide
 
Introduction To Programming with Python-3
Introduction To Programming with Python-3Introduction To Programming with Python-3
Introduction To Programming with Python-3
 
Python (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualizePython (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualize
 
Improve Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptxImprove Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptx
 
TOPIC-2-Expression Variable Assignment Statement.pdf
TOPIC-2-Expression Variable Assignment Statement.pdfTOPIC-2-Expression Variable Assignment Statement.pdf
TOPIC-2-Expression Variable Assignment Statement.pdf
 
Python for beginners
Python for beginnersPython for beginners
Python for beginners
 
02python.ppt
02python.ppt02python.ppt
02python.ppt
 
02python.ppt
02python.ppt02python.ppt
02python.ppt
 
Python 3.x quick syntax guide
Python 3.x quick syntax guidePython 3.x quick syntax guide
Python 3.x quick syntax guide
 
Intro to Python Programming Language
Intro to Python Programming LanguageIntro to Python Programming Language
Intro to Python Programming Language
 

Plus de sunilchute1

Programming construction tools
Programming construction toolsProgramming construction tools
Programming construction toolssunilchute1
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structuresunilchute1
 
Sorting method data structure
Sorting method data structureSorting method data structure
Sorting method data structuresunilchute1
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structuresunilchute1
 
Input output statement
Input output statementInput output statement
Input output statementsunilchute1
 
Call by value and call by reference in java
Call by value and call by reference in javaCall by value and call by reference in java
Call by value and call by reference in javasunilchute1
 
Constructors in java
Constructors in javaConstructors in java
Constructors in javasunilchute1
 
Basic of c language
Basic of c languageBasic of c language
Basic of c languagesunilchute1
 

Plus de sunilchute1 (10)

Programming construction tools
Programming construction toolsProgramming construction tools
Programming construction tools
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structure
 
Sorting method data structure
Sorting method data structureSorting method data structure
Sorting method data structure
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structure
 
Input output statement
Input output statementInput output statement
Input output statement
 
Call by value and call by reference in java
Call by value and call by reference in javaCall by value and call by reference in java
Call by value and call by reference in java
 
Java method
Java methodJava method
Java method
 
Constructors in java
Constructors in javaConstructors in java
Constructors in java
 
C loops
C loopsC loops
C loops
 
Basic of c language
Basic of c languageBasic of c language
Basic of c language
 

Dernier

TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 

Dernier (20)

TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 

Basic data types in python

  • 1. BASIC DATA TYPES IN PYTHON PROF. SUNIL D. CHUTE HEAD DEPT OF COMPUTER SCIENC M.G. COLLEGE ARMORI
  • 2. BASIC DATA TYPES IN PYTHON  Data types are the classification or categorization of data items. It represents the kind of value that tells what operations can be performed on a particular data. Since everything is an object in Python programming, data types are actually classes and variables are instance (object) of these classes.
  • 3. One way to categorize these basic data types is in one of four groups:  Numeric: int, float and the less frequently encountered complex  Sequence: str (string), list and tuple  Boolean: (True or False)  Dictionary: dict(dictionary) data type, consisting of (key, value) pairs NOTE: It's important to point out that Python usually doesn't require you to specify what data type you are using and will assign a data type to your variable based on what it thinks you meant. An equally important thing to point out is that Python is a "loosely/weakly typed" programming language, meaning that a variable can change its type over the course of the program's execution, which isn't the case with "strongly typed" programming languages (such as Java or C++).
  • 4.
  • 5. NUMERIC DATA TYPES These data types are fairly straight-forward and represent numeric values. These can be decimal values, floating point values or even complex numbers.  Integer Data Type - int The int data type deals with integers values. This means values like 0, 1, -2 and -15, and not numbers like 0.5, 1.01, - 10.8, etc. If you give Python the following code, it will conclude that a is an integer and will assign the int data type to it: >>> x = 5 >>> type(x) <class 'int'> We could have been more specific and said something along these lines, to make sure Python understood our 5 as an integer, though, it'll automatically do this exact same thing under the hood:
  • 6. >>> x = int(5) >>> type(x) <class 'int‘> It's worth noting that Python treats any sequence of numbers (without a prefix) as a decimal number. This sequence, in fact, isn't constrained. That is to say, unlike in some other languages like Java, the value of the int doesn't have a maximum value - it's unbounded. The sys.maxsize may sound counterintuitive then, since it implies that that's the maximum value of an integer, though, it isn't. >>> x = sys.maxsize >>> x 2147483647 This appears to be a 32-bit signed binary integer value, though, let's see what happens if we assign a higher number to x: >>> x = sys.maxsize >>> x+1 2147483648
  • 7. In fact, we can even go as far as: >>> y = sys.maxsize + sys.maxsize >>> y 4294967294 The only real limit to how big an integer can be is the memory of the machine you're running Python on.  Prefixing Integers What happens when you'd like to pack a numeric value in a different form? You can prefix a sequence of numbers and tell Python to treat them in a different system. More specifically, the prefixes:  0b or 0B - Will turn your integer into Binary  0o or 0O - Will turn your integer into Octal  0x or 0X - Will turn your integer into Hexadecimal
  • 8.  # Decimal value of 5 >>> x = 5 >>> x 5  # Binary value of 1 >>> x = 0b001 >>> x 1  # Octal value of 5 >>> x = 0o5 >>> x 5  # Hexadecimal value of 10 >>> x = 0x10 >>> x 16
  • 9. FLOATING POINT DATA TYPE - FLOAT  The float type in Python designates a floating-point number. float values are specified with a decimal point. Optionally, the character e or E followed by a positive or negative integer may be appended to specify scientific notation Ex.1 >>> 4.2 4.2 >>> type(4.2) <class 'float'> Ex.2 >>> 4. 4.0 Ex.3 >>> .2 0.2 Ex.4>>> .4e7 4000000.0 >>> type(.4e7) <class 'float'> Ex.5>>> 4.2e-4
  • 10. COMPLEX NUMBERS  Complex numbers are specified as <real part>+<imaginary part>j. Ex. >>> 2+3j (2+3j) >>> type(2+3j) <class 'complex'>
  • 11. STRINGS  Strings are sequences of character data. The string type in Python is called str.  String literals may be delimited using either single or double quotes. All the characters between the opening delimiter and matching closing delimiter are part of the string: Ex.>>> print("I am a string.") I am a string. >>> type("I am a string.") <class 'str'> Ex.>>> print('I am too.') I am too. >>> type('I am too.') <class 'str'>
  • 12.  A string in Python can contain as many characters as you wish. The only limit is your machine’s memory resources. A string can also be empty: Ex. >>> '' ''  What if you want to include a quote character as part of the string itself? Your first impulse might be to try something like this: Ex.>>> print('This string contains a single quote (') character.') SyntaxError: invalid syntax Ex. >>> mystring = "This is not my first String" >>> print (mystring); This is not my first String
  • 13.  to join two or more strings. Ex.>>> print ("Hello" + "World"); HelloWorld Ex. >>> s1 = "Name Python " >>> s2 = "had been adapted " >>> s3 = "from Monty Python" >>> print (s1 + s2 + s3) Name Python had been adapted from Monty Python
  • 14.  use input() function Ex.>>> n = input("Number of times you want the text to repeat: ") Number of times you want the text to repeat: >>> print ("Text"*n); TextTextTextTextText  Check existence of a character or a sub- string in a string Ex.>>> "won" in "India won the match" True
  • 15. PYTHON LIST DATA TYPE  List is an ordered sequence of items. It is one of the most used datatype in Python and is very flexible. All the items in a list do not need to be of the same type.  Declaring a list is pretty straight forward. Items separated by commas are enclosed within brackets [ ]. Ex. a = [1, 2.2, 'python'] We can use the slicing operator [ ] to extract an item or a range of items from a list. The index starts from 0 in Python.
  • 16.
  • 17. PYTHON TUPLE DATA TYPE  Tuple is an ordered sequence of items same as a list. The only difference is that tuples are immutable. Tuples once created cannot be modified.  Tuples are used to write-protect data and are usually faster than lists as they cannot change dynamically.  It is defined within parentheses () where items are separated by commas. Ex. t = (5,'program', 1+3j)
  • 18.  We can use the slicing operator [] to extract items but we cannot change its value.
  • 19. PYTHON SET DATA TYPE  Set is an unordered collection of unique items. Set is defined by values separated by comma inside braces { }. Items in a set are not ordered.  A set is created by placing all the items (elements) inside curly braces {}, separated by comma, or by using the built- in set() function.  It can have any number of items and they may be of different types (integer, float, tuple, string etc.). But a set cannot have mutable
  • 20.
  • 21.
  • 22. PYTHON DICTIONARY DATA TYPE  Python dictionary is an unordered collection of items. Each item of a dictionary has a key/value pair.  It is generally used when we have a huge amount of data. Dictionaries are optimized for retrieving data. We must know the key to retrieve the value.  In Python, dictionaries are defined within braces {} with each item being a pair in the form key:value. Key and value can be of any type.
  • 23.