SlideShare a Scribd company logo
1 of 11
Knowing Data Types
CSM 1231
Using the type()
• Data types can be shown using the type() function, e.g.,
Type Conversion (Type Cast)
• Conversion of value of one type to another
• We are used to int ↔ float conversion in Math
• Integer 3 is treated as float 3.0 when a real number is expected
• Float 3.6 is truncated as 3, or rounded off as 4 for integer contexts
• Type names are used as type converter functions
Type Conversion Examples
Note that float to int conversion
is truncation, not rounding off
Input
• Take as argument a string to print as a prompt
• Returns the user typed value as a string
• details of how to process user string later
IN[1]:
IN[2]:
IN[3]:
( )
Type Conversion and Input
Operators
• Arithmetic
• Comparison
• Assignment
• Logical
• Membership
• Identity
+ - * // / % **
== != > < >= <=
= += -= *= //= /= %= **=
and or not
in not in
is is not
The // operator
• Also referred to as “integer division”
• Result is a whole integer (floor of real division)
• But the type need not be int
• the integral part of the real division
• rounded towards minus infinity (−∞)
• Examples
9//4 is 2 (-1)//2 is -1 (-1)//(-2) is 0
1//2 is 0 1//(-2) is -1 9//4.5 is 2.0
Class Quiz
• What is the value of expression:
a) Run time crash/error
b) I don’t know / I don’t care
c) False
d) True
(5<2) and (3/0 > 1)
The correct answer is
False
Short-circuit Evaluation
• Do not evaluate the second operand of binary short-circuit logical
operator if the result can be deduced from the first operand
• Also applies to nested logical operators
not( (2>5) and (3/0 > 1) ) or (4/0 < 2)
Evaluates to true
false false
true true
Assignment
• Write a bank program that computes and prints interests for users
• The program should take-in the principal amount, interest rate and time
period from the users

More Related Content

Similar to Data types in Python.pptx

Similar to Data types in Python.pptx (20)

Intro To C++ - Cass 11 - Converting between types, formatting floating point,...
Intro To C++ - Cass 11 - Converting between types, formatting floating point,...Intro To C++ - Cass 11 - Converting between types, formatting floating point,...
Intro To C++ - Cass 11 - Converting between types, formatting floating point,...
 
Intro To C++ - Class 11 - Converting between types, formatting floating point...
Intro To C++ - Class 11 - Converting between types, formatting floating point...Intro To C++ - Class 11 - Converting between types, formatting floating point...
Intro To C++ - Class 11 - Converting between types, formatting floating point...
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
 
Lamborghini Veneno Allegheri #2004@f**ck
Lamborghini Veneno Allegheri #2004@f**ckLamborghini Veneno Allegheri #2004@f**ck
Lamborghini Veneno Allegheri #2004@f**ck
 
Lecture 05.pptx
Lecture 05.pptxLecture 05.pptx
Lecture 05.pptx
 
Introduction to C ++.pptx
Introduction to C ++.pptxIntroduction to C ++.pptx
Introduction to C ++.pptx
 
Data Type in C Programming
Data Type in C ProgrammingData Type in C Programming
Data Type in C Programming
 
Python4HPC.pptx
Python4HPC.pptxPython4HPC.pptx
Python4HPC.pptx
 
Aspdot
AspdotAspdot
Aspdot
 
C language
C languageC language
C language
 
Basics of c++ Programming Language
Basics of c++ Programming LanguageBasics of c++ Programming Language
Basics of c++ Programming Language
 
Type Conversion, Precedence and Associativity
Type Conversion, Precedence and AssociativityType Conversion, Precedence and Associativity
Type Conversion, Precedence and Associativity
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Token and operators
Token and operatorsToken and operators
Token and operators
 
Data type
Data typeData type
Data type
 
Basic elements of java
Basic elements of java Basic elements of java
Basic elements of java
 
Python4HPC.pptx
Python4HPC.pptxPython4HPC.pptx
Python4HPC.pptx
 
Java chapter 2
Java chapter 2Java chapter 2
Java chapter 2
 
C sharp part 001
C sharp part 001C sharp part 001
C sharp part 001
 
Prog1-L2.pptx
Prog1-L2.pptxProg1-L2.pptx
Prog1-L2.pptx
 

More from DukeCalvin (7)

Computer Science Ethics: Deontological ethics.pptx
Computer Science Ethics: Deontological ethics.pptxComputer Science Ethics: Deontological ethics.pptx
Computer Science Ethics: Deontological ethics.pptx
 
COMPUTER SCIENCE: PACIFISM IN ETHICS AND PEACE STUDIES
COMPUTER SCIENCE: PACIFISM IN ETHICS AND PEACE STUDIESCOMPUTER SCIENCE: PACIFISM IN ETHICS AND PEACE STUDIES
COMPUTER SCIENCE: PACIFISM IN ETHICS AND PEACE STUDIES
 
Topic 4 Data Processing.pptx
Topic 4 Data Processing.pptxTopic 4 Data Processing.pptx
Topic 4 Data Processing.pptx
 
Introduction to IoT.pptx
Introduction to IoT.pptxIntroduction to IoT.pptx
Introduction to IoT.pptx
 
Data structures and algorithms Module-1.pdf
Data structures and algorithms Module-1.pdfData structures and algorithms Module-1.pdf
Data structures and algorithms Module-1.pdf
 
Python-L1.pptx
Python-L1.pptxPython-L1.pptx
Python-L1.pptx
 
Entreprenuership skill development.pptx
Entreprenuership skill development.pptxEntreprenuership skill development.pptx
Entreprenuership skill development.pptx
 

Recently uploaded

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
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
QucHHunhnh
 

Recently uploaded (20)

Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
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
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
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
 
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
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
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...
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 

Data types in Python.pptx

  • 2. Using the type() • Data types can be shown using the type() function, e.g.,
  • 3. Type Conversion (Type Cast) • Conversion of value of one type to another • We are used to int ↔ float conversion in Math • Integer 3 is treated as float 3.0 when a real number is expected • Float 3.6 is truncated as 3, or rounded off as 4 for integer contexts • Type names are used as type converter functions
  • 4. Type Conversion Examples Note that float to int conversion is truncation, not rounding off
  • 5. Input • Take as argument a string to print as a prompt • Returns the user typed value as a string • details of how to process user string later IN[1]: IN[2]: IN[3]: ( )
  • 7. Operators • Arithmetic • Comparison • Assignment • Logical • Membership • Identity + - * // / % ** == != > < >= <= = += -= *= //= /= %= **= and or not in not in is is not
  • 8. The // operator • Also referred to as “integer division” • Result is a whole integer (floor of real division) • But the type need not be int • the integral part of the real division • rounded towards minus infinity (−∞) • Examples 9//4 is 2 (-1)//2 is -1 (-1)//(-2) is 0 1//2 is 0 1//(-2) is -1 9//4.5 is 2.0
  • 9. Class Quiz • What is the value of expression: a) Run time crash/error b) I don’t know / I don’t care c) False d) True (5<2) and (3/0 > 1) The correct answer is False
  • 10. Short-circuit Evaluation • Do not evaluate the second operand of binary short-circuit logical operator if the result can be deduced from the first operand • Also applies to nested logical operators not( (2>5) and (3/0 > 1) ) or (4/0 < 2) Evaluates to true false false true true
  • 11. Assignment • Write a bank program that computes and prints interests for users • The program should take-in the principal amount, interest rate and time period from the users