SlideShare a Scribd company logo
Chapter-2
Data Types
Comments
Data Types
Comments
Single Line Comments
● Starts with # symbol
● Comments are non-executable statements
1 #To find sum of two numbers
2 a = 10 #Store 10 into variable 'a'
Comments
Multi Line Comments
● Version-1
● Version-2
● Version-3
1 #To find sum of two numbers
2 #This is multi-line comments
3 #One more commented line
4 """
5 This is first line
6 This second line
7 Finally comes third
8 """
4 '''
5 This is first line
6 This second line
7 Finally comes third
8 '''
Docstrings
Multi Line Comments
● Python supports only single line commenting
● Strings enclosed within ''' … ''' or """ … """, if not assigned to any variable, they are removed from
memory by the GC
● Also called as Documentation Strings OR docstrings
● Useful to create API file
Command to Create the html file
-------------------------------
py -m pydoc -w 1_Docstrings
-m: Module
-w: To create the html file
How python sees variables
Data-Types
None Type
● None data-type represents an object that does not contain any value
● In Java, it is called as NULL Object
● In Python, it is called as NONE Object
● In boolean expression, NONE data-type represents ‘False’
● Example:
○ a = “”
Data-Types
Numeric Type
● int
○ No limit for the size of an int datatype
○ Can store very large numbers conveniently
○ Only limited by the memory of the system
○ Example:
■ a = 20
Data-Types
Numeric Type
● float
○ Example-1:
■ A = 56.78
○ Example-2:
■ B = 22.55e3 ⇔ B = 22.55 x 10^3
Data-Types
Numeric Type
● Complex
○ Written in the form a + bj OR a + bJ
○ a and b may be ints or floats
○ Example:
■ c = 1 + 5j
■ c = -1 - 4.4j
Representation
Binary, Octal, Hexadecimal
● Binary
○ Prefixed with 0b OR 0B
■ 0b11001100
■ 0B10101100
● Octal
○ Prefixed with 0o OR 0O
■ 0o134
■ 0O345
● Hexadecimal
○ Prefixed with 0x OR 0X
■ 0xAB
■ 0Xab
Conversion
Explicit
● Coercion / type conversions
○ Example-1:
○ Example-2:
x = 15.56
int(x) #Will convert into int and display 15
x = 15
float(x) #Will convert into float and display 15.0
Conversion
Explicit
● Coercion / type conversions
○ Example-3:
○ Example-4:
a = 15.56
complex(a) #Will convert into complex and display (15.56 + 0j)
a = 15
b = 3
complex(a, b) #Will convert into complex and display (15 + 3j)
Conversion
Explicit
● Coercion / type conversions
○ Example-5: To convert string into integer
○ Syntax: int(string, base)
○ Other functions are
■ bin(): To convert int to binary
■ oct(): To convert oct to binary
■ hex(): To convert hex to binary
str = “1c2”
n = int(str, 16)
print(n)
bool Data-Type
● Two bool values
○ True: Internally represented as 1
○ False: Internally represented as 0
● Blank string “” also represented as False
● Example-1:
a = 10
b = 20
if ( a < b):
print(“Hello”)
bool Data-Type
● Example-2:
● Example-3:
a = 10 > 5
print(a) #Prints True
a = 5 > 10
print(a) #Prints False
print(True + True) #Prints 2
print(True + False) #Prints 1
Sequences
Data Types
Sequences
str
● str represents the string data-type
● Example-1:
● Example-2:
3 str = "Welcome to Python"
4 print(str)
5
6 str = 'Welcome to Python'
7 print(str)
3 str = """
4 Welcome to Python
5 I am very big
6 """
7 print(str)
8
9 str = '''
10 Welcome to Python
11 I am very big
12 '''
13 print(str)
Sequences
str
● Example-3:
● Example-4:
3 str = "This is 'core' Python"
4 print(str)
5
6 str = 'This is "core" Python'
7 print(str)
3 s = "Welcome to Python"
4
5 #Print the whole string
6 print(s)
7
8 #Print the character indexed @ 2
9 print(s[2])
10
11 #Print range of characters
12 print(s[2:5]) #Prints 2nd to 4th character
13
14 #Print from given index to end
15 print(s[5: ])
16
17 #Prints first character from end(Negative indexing)
18 print(s[-1])
Sequences
str
● Example-5:
3 s = "Emertxe"
4
5 print(s * 3)
bytes Data-types
Data Types
Sequences
bytes
● bytes represents a group of byte numbers
● A byte is any positive number between 0 and 255(Inclusive)
● Example-1:
3 #Create the list of byte type array
4 items = [10, 20, 30, 40, 50]
5
6 #Convert the list into bytes type array
7 x = bytes(items)
8
9 #Print the array
10 for i in x:
11 print(i)
Sequences
bytes
● Modifying any item in the byte type is not possible
● Example-2:
3 #Create the list of byte type array
4 items = [10, 20, 30, 40, 50]
5
6 #Convert the list into bytes type array
7 x = bytes(items)
8
9 #Modifying x[0]
10 x[0] = 11 #Gives an error
bytearray Data-type
Data Types
Sequences
bytearray
● bytearray is similar to bytes
● Difference is items in bytearray is modifiable
● Example-1:
3 #Create the list of byte type array
4 items = [10, 20, 30, 40, 50]
5
6 #Convert the list into bytes type array
7 x = bytearray(items)
8
9 x[0] = 55 #Allowed
10
11 #Print the array
12 for i in x:
13 print(i)
list Data-type
Data Types
Sequences
list
● list is similar to array, but contains items of different data-types
● list can grow dynamically at run-time, but arrays cannot
● Example-1:
3 #Create the list
4 list = [10, -20, 15.5, 'Emertxe', "Python"]
5
6 print(list)
7
8 print(list[0])
9
10 print(list[1:3])
11
12 print(list[-2])
13
14 print(list * 2)
tuple Data-type
Data Types
Sequences
tuple
● tuple is similar to list, but items cannot be modified
● tuple is read-only list
● tuple are enclosed within ()
● Example-1:
3 #Create the tuple
4 tpl = (10, -20, 12.34, "Good", 'Elegant')
5
6 #print the list
7 for i in tpl:
8 print(i)
range Data-type
Data Types
Sequences
range
● range represents sequence of numbers
● Numbers in range are not modifiable
● Example-1:
3 #Create the range of numbers
4 r = range(10)
5
6 #Print the range
7 for i in r:
8 print(i)
Sequences
range
● Example-2:
● Example-3:
10 #Print the range with step size 2
11 r = range(20, 30, 2)
12
13 #Print the range
14 for i in r:
15 print(i)
17 #Create the list with range of numbers
18 lst = list(range(10))
19 print(lst)
Sets
Data Types
Sets
● Set is an unordered collection of elements
● Elements may not appear in the same order as they are entered into the set
● Set does not accept duplicate items
● Types
○ set datatype
○ frozenset datatype
Sets
set
● Example-1:
● Example-2:
● Example-3:
3 #Create the set
4 s = {10, 20, 30, 40, 50}
5 print(s) #Order will not be maintained
8 ch = set("Hello")
9 print(ch) #Duplicates are removed
11 #Convert list into set
12 lst = [1, 2, 3, 3, 4]
13 s = set(lst)
14 print(s)
Sets
set
● Example-5:
● Example-6:
11 #Convert list into set
12 lst = [1, 2, 3, 3, 4]
13 s = set(lst)
14 print(s)
16 #Addition of items into the array
17 s.update([50, 60])
18 print(s)
19
20 #Remove the item 50
21 s.remove(50)
22 print(s)
Sets
frozenset
● Similar to that of set, but cannot modify any item
● Example-1:
● Example-2:
2 s = {1, 2, 3, 4}
3 print(s)
4
5 #Creating the frozen set
6 fs = frozenset(s)
7 print(fs)
9 #One more methos to create the frozen set
10 fs = frozenset("abcdef")
11 print(fs)
Mapping Types
Data Types
Mapping
● Map represents group of items in the form of key: value pair
● dict data-type is an example for map
● Example-1:
● Example-2:
3 #Create the dictionary
4 d = {10: 'Amar', 11: 'Anthony', 12: 'Akbar'}
5 print(d)
6
7 #Print using the key
8 print(d[11])
10 #Print all the keys
11 print(d.keys())
12
13 #Print all the values
14 print(d.values())
Mapping
● Example-3:
● Example-4:
16 #Change the value
17 d[10] = 'Akul'
18 print(d)
19
20 #Delete the item
21 del d[10]
22 print(d)
24 #create the dictionary and populate dynamically
25 d = {}
26 d[10] = "Ram"
27
28 print(d)
Determining the Datatype
Data Types
Determining Datatype of a Variable
● type()
● Example-1:
3 a = 10
4 print(type(a))
5
6 b = 12.34
7 print(type(b))
8
9 l = [1, 2, 3]
10 print(type(l))

More Related Content

What's hot

Python programming : Standard Input and Output
Python programming : Standard Input and OutputPython programming : Standard Input and Output
Python programming : Standard Input and Output
Emertxe Information Technologies Pvt Ltd
 
Variables in python
Variables in pythonVariables in python
Variables in python
Jaya Kumari
 
File Handling Python
File Handling PythonFile Handling Python
File Handling Python
Akhil Kaushik
 
Python Pandas
Python PandasPython Pandas
Python Pandas
Sunil OS
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
Mohammed Sikander
 
Looping statement in python
Looping statement in pythonLooping statement in python
Looping statement in python
RaginiJain21
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in Python
Sujith Kumar
 
Python
PythonPython
Python
Aashish Jain
 
List,tuple,dictionary
List,tuple,dictionaryList,tuple,dictionary
List,tuple,dictionary
nitamhaske
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
Matt Harrison
 
Date and Time Module in Python | Edureka
Date and Time Module in Python | EdurekaDate and Time Module in Python | Edureka
Date and Time Module in Python | Edureka
Edureka!
 
Looping Statements and Control Statements in Python
Looping Statements and Control Statements in PythonLooping Statements and Control Statements in Python
Looping Statements and Control Statements in Python
PriyankaC44
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
imtiazalijoono
 
Python: Modules and Packages
Python: Modules and PackagesPython: Modules and Packages
Python: Modules and Packages
Damian T. Gordon
 
Python dictionary
Python   dictionaryPython   dictionary
Python dictionary
Mohammed Sikander
 
Loops in Python.pptx
Loops in Python.pptxLoops in Python.pptx
Python Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, DictionaryPython Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, Dictionary
Soba Arjun
 
Lesson 02 python keywords and identifiers
Lesson 02   python keywords and identifiersLesson 02   python keywords and identifiers
Lesson 02 python keywords and identifiers
Nilimesh Halder
 
2D Array
2D Array 2D Array
2D Array
Ehatsham Riaz
 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
Emertxe Information Technologies Pvt Ltd
 

What's hot (20)

Python programming : Standard Input and Output
Python programming : Standard Input and OutputPython programming : Standard Input and Output
Python programming : Standard Input and Output
 
Variables in python
Variables in pythonVariables in python
Variables in python
 
File Handling Python
File Handling PythonFile Handling Python
File Handling Python
 
Python Pandas
Python PandasPython Pandas
Python Pandas
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
 
Looping statement in python
Looping statement in pythonLooping statement in python
Looping statement in python
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in Python
 
Python
PythonPython
Python
 
List,tuple,dictionary
List,tuple,dictionaryList,tuple,dictionary
List,tuple,dictionary
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
 
Date and Time Module in Python | Edureka
Date and Time Module in Python | EdurekaDate and Time Module in Python | Edureka
Date and Time Module in Python | Edureka
 
Looping Statements and Control Statements in Python
Looping Statements and Control Statements in PythonLooping Statements and Control Statements in Python
Looping Statements and Control Statements in Python
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
 
Python: Modules and Packages
Python: Modules and PackagesPython: Modules and Packages
Python: Modules and Packages
 
Python dictionary
Python   dictionaryPython   dictionary
Python dictionary
 
Loops in Python.pptx
Loops in Python.pptxLoops in Python.pptx
Loops in Python.pptx
 
Python Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, DictionaryPython Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, Dictionary
 
Lesson 02 python keywords and identifiers
Lesson 02   python keywords and identifiersLesson 02   python keywords and identifiers
Lesson 02 python keywords and identifiers
 
2D Array
2D Array 2D Array
2D Array
 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
 

Similar to Python : Data Types

Python bible
Python biblePython bible
Python bible
adarsh j
 
Introduction To Programming with Python
Introduction To Programming with PythonIntroduction To Programming with Python
Introduction To Programming with Python
Sushant Mane
 
Python 101
Python 101Python 101
Python 101
Prashant Jamkhande
 
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docxINFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
carliotwaycave
 
Pythonlearn-08-Lists.pptx
Pythonlearn-08-Lists.pptxPythonlearn-08-Lists.pptx
Pythonlearn-08-Lists.pptx
MihirDatir
 
The Ring programming language version 1.3 book - Part 11 of 88
The Ring programming language version 1.3 book - Part 11 of 88The Ring programming language version 1.3 book - Part 11 of 88
The Ring programming language version 1.3 book - Part 11 of 88
Mahmoud Samir Fayed
 
Python crush course
Python crush coursePython crush course
Python crush course
Mohammed El Rafie Tarabay
 
PYTHON.pptx
PYTHON.pptxPYTHON.pptx
PYTHON.pptx
rohithprakash16
 
Python Essentials - PICT.pdf
Python Essentials - PICT.pdfPython Essentials - PICT.pdf
Python Essentials - PICT.pdf
Prashant Jamkhande
 
Basics of Python Programming
Basics of Python ProgrammingBasics of Python Programming
Basics of Python Programming
ManishJha237
 
Python revision tour II
Python revision tour IIPython revision tour II
Python revision tour II
Mr. Vikram Singh Slathia
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
Ahmed Salama
 
The Ring programming language version 1.3 book - Part 12 of 88
The Ring programming language version 1.3 book - Part 12 of 88The Ring programming language version 1.3 book - Part 12 of 88
The Ring programming language version 1.3 book - Part 12 of 88
Mahmoud Samir Fayed
 
Python
PythonPython
Visual Programing basic lectures 7.pptx
Visual Programing basic lectures  7.pptxVisual Programing basic lectures  7.pptx
Visual Programing basic lectures 7.pptx
Mrhaider4
 
Basics of python 3
Basics of python 3Basics of python 3
Basics of python 3
V.N.S. Satya Teja
 
23UCACC11 Python Programming (MTNC) (BCA)
23UCACC11 Python Programming (MTNC) (BCA)23UCACC11 Python Programming (MTNC) (BCA)
23UCACC11 Python Programming (MTNC) (BCA)
ssuser7f90ae
 
Lecture 2 coal sping12
Lecture 2 coal sping12Lecture 2 coal sping12
Lecture 2 coal sping12Rabia Khalid
 
The Ring programming language version 1.2 book - Part 10 of 84
The Ring programming language version 1.2 book - Part 10 of 84The Ring programming language version 1.2 book - Part 10 of 84
The Ring programming language version 1.2 book - Part 10 of 84
Mahmoud Samir Fayed
 

Similar to Python : Data Types (20)

Python bible
Python biblePython bible
Python bible
 
Introduction To Programming with Python
Introduction To Programming with PythonIntroduction To Programming with Python
Introduction To Programming with Python
 
Python 101
Python 101Python 101
Python 101
 
Python lecture 05
Python lecture 05Python lecture 05
Python lecture 05
 
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docxINFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
 
Pythonlearn-08-Lists.pptx
Pythonlearn-08-Lists.pptxPythonlearn-08-Lists.pptx
Pythonlearn-08-Lists.pptx
 
The Ring programming language version 1.3 book - Part 11 of 88
The Ring programming language version 1.3 book - Part 11 of 88The Ring programming language version 1.3 book - Part 11 of 88
The Ring programming language version 1.3 book - Part 11 of 88
 
Python crush course
Python crush coursePython crush course
Python crush course
 
PYTHON.pptx
PYTHON.pptxPYTHON.pptx
PYTHON.pptx
 
Python Essentials - PICT.pdf
Python Essentials - PICT.pdfPython Essentials - PICT.pdf
Python Essentials - PICT.pdf
 
Basics of Python Programming
Basics of Python ProgrammingBasics of Python Programming
Basics of Python Programming
 
Python revision tour II
Python revision tour IIPython revision tour II
Python revision tour II
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
The Ring programming language version 1.3 book - Part 12 of 88
The Ring programming language version 1.3 book - Part 12 of 88The Ring programming language version 1.3 book - Part 12 of 88
The Ring programming language version 1.3 book - Part 12 of 88
 
Python
PythonPython
Python
 
Visual Programing basic lectures 7.pptx
Visual Programing basic lectures  7.pptxVisual Programing basic lectures  7.pptx
Visual Programing basic lectures 7.pptx
 
Basics of python 3
Basics of python 3Basics of python 3
Basics of python 3
 
23UCACC11 Python Programming (MTNC) (BCA)
23UCACC11 Python Programming (MTNC) (BCA)23UCACC11 Python Programming (MTNC) (BCA)
23UCACC11 Python Programming (MTNC) (BCA)
 
Lecture 2 coal sping12
Lecture 2 coal sping12Lecture 2 coal sping12
Lecture 2 coal sping12
 
The Ring programming language version 1.2 book - Part 10 of 84
The Ring programming language version 1.2 book - Part 10 of 84The Ring programming language version 1.2 book - Part 10 of 84
The Ring programming language version 1.2 book - Part 10 of 84
 

More from Emertxe Information Technologies Pvt Ltd

Career Transition (1).pdf
Career Transition (1).pdfCareer Transition (1).pdf
Career Transition (1).pdf
Emertxe Information Technologies Pvt Ltd
 
10_isxdigit.pdf
10_isxdigit.pdf10_isxdigit.pdf

More from Emertxe Information Technologies Pvt Ltd (20)

premium post (1).pdf
premium post (1).pdfpremium post (1).pdf
premium post (1).pdf
 
Career Transition (1).pdf
Career Transition (1).pdfCareer Transition (1).pdf
Career Transition (1).pdf
 
10_isxdigit.pdf
10_isxdigit.pdf10_isxdigit.pdf
10_isxdigit.pdf
 
01_student_record.pdf
01_student_record.pdf01_student_record.pdf
01_student_record.pdf
 
02_swap.pdf
02_swap.pdf02_swap.pdf
02_swap.pdf
 
01_sizeof.pdf
01_sizeof.pdf01_sizeof.pdf
01_sizeof.pdf
 
07_product_matrix.pdf
07_product_matrix.pdf07_product_matrix.pdf
07_product_matrix.pdf
 
06_sort_names.pdf
06_sort_names.pdf06_sort_names.pdf
06_sort_names.pdf
 
05_fragments.pdf
05_fragments.pdf05_fragments.pdf
05_fragments.pdf
 
04_magic_square.pdf
04_magic_square.pdf04_magic_square.pdf
04_magic_square.pdf
 
03_endianess.pdf
03_endianess.pdf03_endianess.pdf
03_endianess.pdf
 
02_variance.pdf
02_variance.pdf02_variance.pdf
02_variance.pdf
 
01_memory_manager.pdf
01_memory_manager.pdf01_memory_manager.pdf
01_memory_manager.pdf
 
09_nrps.pdf
09_nrps.pdf09_nrps.pdf
09_nrps.pdf
 
11_pangram.pdf
11_pangram.pdf11_pangram.pdf
11_pangram.pdf
 
10_combinations.pdf
10_combinations.pdf10_combinations.pdf
10_combinations.pdf
 
08_squeeze.pdf
08_squeeze.pdf08_squeeze.pdf
08_squeeze.pdf
 
07_strtok.pdf
07_strtok.pdf07_strtok.pdf
07_strtok.pdf
 
06_reverserec.pdf
06_reverserec.pdf06_reverserec.pdf
06_reverserec.pdf
 
05_reverseiter.pdf
05_reverseiter.pdf05_reverseiter.pdf
05_reverseiter.pdf
 

Recently uploaded

The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 

Recently uploaded (20)

The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 

Python : Data Types

  • 3. Comments Single Line Comments ● Starts with # symbol ● Comments are non-executable statements 1 #To find sum of two numbers 2 a = 10 #Store 10 into variable 'a'
  • 4. Comments Multi Line Comments ● Version-1 ● Version-2 ● Version-3 1 #To find sum of two numbers 2 #This is multi-line comments 3 #One more commented line 4 """ 5 This is first line 6 This second line 7 Finally comes third 8 """ 4 ''' 5 This is first line 6 This second line 7 Finally comes third 8 '''
  • 5. Docstrings Multi Line Comments ● Python supports only single line commenting ● Strings enclosed within ''' … ''' or """ … """, if not assigned to any variable, they are removed from memory by the GC ● Also called as Documentation Strings OR docstrings ● Useful to create API file Command to Create the html file ------------------------------- py -m pydoc -w 1_Docstrings -m: Module -w: To create the html file
  • 6. How python sees variables
  • 7. Data-Types None Type ● None data-type represents an object that does not contain any value ● In Java, it is called as NULL Object ● In Python, it is called as NONE Object ● In boolean expression, NONE data-type represents ‘False’ ● Example: ○ a = “”
  • 8. Data-Types Numeric Type ● int ○ No limit for the size of an int datatype ○ Can store very large numbers conveniently ○ Only limited by the memory of the system ○ Example: ■ a = 20
  • 9. Data-Types Numeric Type ● float ○ Example-1: ■ A = 56.78 ○ Example-2: ■ B = 22.55e3 ⇔ B = 22.55 x 10^3
  • 10. Data-Types Numeric Type ● Complex ○ Written in the form a + bj OR a + bJ ○ a and b may be ints or floats ○ Example: ■ c = 1 + 5j ■ c = -1 - 4.4j
  • 11. Representation Binary, Octal, Hexadecimal ● Binary ○ Prefixed with 0b OR 0B ■ 0b11001100 ■ 0B10101100 ● Octal ○ Prefixed with 0o OR 0O ■ 0o134 ■ 0O345 ● Hexadecimal ○ Prefixed with 0x OR 0X ■ 0xAB ■ 0Xab
  • 12. Conversion Explicit ● Coercion / type conversions ○ Example-1: ○ Example-2: x = 15.56 int(x) #Will convert into int and display 15 x = 15 float(x) #Will convert into float and display 15.0
  • 13. Conversion Explicit ● Coercion / type conversions ○ Example-3: ○ Example-4: a = 15.56 complex(a) #Will convert into complex and display (15.56 + 0j) a = 15 b = 3 complex(a, b) #Will convert into complex and display (15 + 3j)
  • 14. Conversion Explicit ● Coercion / type conversions ○ Example-5: To convert string into integer ○ Syntax: int(string, base) ○ Other functions are ■ bin(): To convert int to binary ■ oct(): To convert oct to binary ■ hex(): To convert hex to binary str = “1c2” n = int(str, 16) print(n)
  • 15. bool Data-Type ● Two bool values ○ True: Internally represented as 1 ○ False: Internally represented as 0 ● Blank string “” also represented as False ● Example-1: a = 10 b = 20 if ( a < b): print(“Hello”)
  • 16. bool Data-Type ● Example-2: ● Example-3: a = 10 > 5 print(a) #Prints True a = 5 > 10 print(a) #Prints False print(True + True) #Prints 2 print(True + False) #Prints 1
  • 18. Sequences str ● str represents the string data-type ● Example-1: ● Example-2: 3 str = "Welcome to Python" 4 print(str) 5 6 str = 'Welcome to Python' 7 print(str) 3 str = """ 4 Welcome to Python 5 I am very big 6 """ 7 print(str) 8 9 str = ''' 10 Welcome to Python 11 I am very big 12 ''' 13 print(str)
  • 19. Sequences str ● Example-3: ● Example-4: 3 str = "This is 'core' Python" 4 print(str) 5 6 str = 'This is "core" Python' 7 print(str) 3 s = "Welcome to Python" 4 5 #Print the whole string 6 print(s) 7 8 #Print the character indexed @ 2 9 print(s[2]) 10 11 #Print range of characters 12 print(s[2:5]) #Prints 2nd to 4th character 13 14 #Print from given index to end 15 print(s[5: ]) 16 17 #Prints first character from end(Negative indexing) 18 print(s[-1])
  • 20. Sequences str ● Example-5: 3 s = "Emertxe" 4 5 print(s * 3)
  • 22. Sequences bytes ● bytes represents a group of byte numbers ● A byte is any positive number between 0 and 255(Inclusive) ● Example-1: 3 #Create the list of byte type array 4 items = [10, 20, 30, 40, 50] 5 6 #Convert the list into bytes type array 7 x = bytes(items) 8 9 #Print the array 10 for i in x: 11 print(i)
  • 23. Sequences bytes ● Modifying any item in the byte type is not possible ● Example-2: 3 #Create the list of byte type array 4 items = [10, 20, 30, 40, 50] 5 6 #Convert the list into bytes type array 7 x = bytes(items) 8 9 #Modifying x[0] 10 x[0] = 11 #Gives an error
  • 25. Sequences bytearray ● bytearray is similar to bytes ● Difference is items in bytearray is modifiable ● Example-1: 3 #Create the list of byte type array 4 items = [10, 20, 30, 40, 50] 5 6 #Convert the list into bytes type array 7 x = bytearray(items) 8 9 x[0] = 55 #Allowed 10 11 #Print the array 12 for i in x: 13 print(i)
  • 27. Sequences list ● list is similar to array, but contains items of different data-types ● list can grow dynamically at run-time, but arrays cannot ● Example-1: 3 #Create the list 4 list = [10, -20, 15.5, 'Emertxe', "Python"] 5 6 print(list) 7 8 print(list[0]) 9 10 print(list[1:3]) 11 12 print(list[-2]) 13 14 print(list * 2)
  • 29. Sequences tuple ● tuple is similar to list, but items cannot be modified ● tuple is read-only list ● tuple are enclosed within () ● Example-1: 3 #Create the tuple 4 tpl = (10, -20, 12.34, "Good", 'Elegant') 5 6 #print the list 7 for i in tpl: 8 print(i)
  • 31. Sequences range ● range represents sequence of numbers ● Numbers in range are not modifiable ● Example-1: 3 #Create the range of numbers 4 r = range(10) 5 6 #Print the range 7 for i in r: 8 print(i)
  • 32. Sequences range ● Example-2: ● Example-3: 10 #Print the range with step size 2 11 r = range(20, 30, 2) 12 13 #Print the range 14 for i in r: 15 print(i) 17 #Create the list with range of numbers 18 lst = list(range(10)) 19 print(lst)
  • 34. Sets ● Set is an unordered collection of elements ● Elements may not appear in the same order as they are entered into the set ● Set does not accept duplicate items ● Types ○ set datatype ○ frozenset datatype
  • 35. Sets set ● Example-1: ● Example-2: ● Example-3: 3 #Create the set 4 s = {10, 20, 30, 40, 50} 5 print(s) #Order will not be maintained 8 ch = set("Hello") 9 print(ch) #Duplicates are removed 11 #Convert list into set 12 lst = [1, 2, 3, 3, 4] 13 s = set(lst) 14 print(s)
  • 36. Sets set ● Example-5: ● Example-6: 11 #Convert list into set 12 lst = [1, 2, 3, 3, 4] 13 s = set(lst) 14 print(s) 16 #Addition of items into the array 17 s.update([50, 60]) 18 print(s) 19 20 #Remove the item 50 21 s.remove(50) 22 print(s)
  • 37. Sets frozenset ● Similar to that of set, but cannot modify any item ● Example-1: ● Example-2: 2 s = {1, 2, 3, 4} 3 print(s) 4 5 #Creating the frozen set 6 fs = frozenset(s) 7 print(fs) 9 #One more methos to create the frozen set 10 fs = frozenset("abcdef") 11 print(fs)
  • 39. Mapping ● Map represents group of items in the form of key: value pair ● dict data-type is an example for map ● Example-1: ● Example-2: 3 #Create the dictionary 4 d = {10: 'Amar', 11: 'Anthony', 12: 'Akbar'} 5 print(d) 6 7 #Print using the key 8 print(d[11]) 10 #Print all the keys 11 print(d.keys()) 12 13 #Print all the values 14 print(d.values())
  • 40. Mapping ● Example-3: ● Example-4: 16 #Change the value 17 d[10] = 'Akul' 18 print(d) 19 20 #Delete the item 21 del d[10] 22 print(d) 24 #create the dictionary and populate dynamically 25 d = {} 26 d[10] = "Ram" 27 28 print(d)
  • 42. Determining Datatype of a Variable ● type() ● Example-1: 3 a = 10 4 print(type(a)) 5 6 b = 12.34 7 print(type(b)) 8 9 l = [1, 2, 3] 10 print(type(l))