python basics! - data types, strings, indexing...administrivia administrivia 3/44 lab #2 tomorrow...
TRANSCRIPT
![Page 1: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/1.jpg)
Python Basics!data types, strings, indexing
CS101 Lecture #3
2016-10-08
![Page 2: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/2.jpg)
Administrivia 1/44
Administrivia
![Page 3: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/3.jpg)
Administrivia
Administrivia 2/44
Homework #2–#6 will be later.
Final answer counts.Answers will be released 18 hours later.
![Page 4: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/4.jpg)
Administrivia
Administrivia 2/44
Homework #2–#6 will be later.Final answer counts.
Answers will be released 18 hours later.
![Page 5: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/5.jpg)
Administrivia
Administrivia 2/44
Homework #2–#6 will be later.Final answer counts.Answers will be released 18 hours later.
![Page 6: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/6.jpg)
Administrivia
Administrivia 3/44
Lab #2 tomorrow Sunday.
Where can you get help in this class?Blackboard forumInstructors in labs and office hours
You don’t need to install Python—but if you do,use Python 3.This is not a “weeder” class—you can succeed!
![Page 7: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/7.jpg)
Administrivia
Administrivia 3/44
Lab #2 tomorrow Sunday.Where can you get help in this class?
Blackboard forumInstructors in labs and office hours
You don’t need to install Python—but if you do,use Python 3.This is not a “weeder” class—you can succeed!
![Page 8: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/8.jpg)
Administrivia
Administrivia 3/44
Lab #2 tomorrow Sunday.Where can you get help in this class?
Blackboard forumInstructors in labs and office hours
You don’t need to install Python—but if you do,use Python 3.
This is not a “weeder” class—you can succeed!
![Page 9: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/9.jpg)
Administrivia
Administrivia 3/44
Lab #2 tomorrow Sunday.Where can you get help in this class?
Blackboard forumInstructors in labs and office hours
You don’t need to install Python—but if you do,use Python 3.This is not a “weeder” class—you can succeed!
![Page 10: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/10.jpg)
Quick Review & A Bit New 4/44
Quick Review & A Bit New
![Page 11: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/11.jpg)
How Assignment Works
Quick Review & A Bit New 5/44
x = 10
y = x * xx * x = y
x,y = y,x # a neat trick
![Page 12: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/12.jpg)
How Assignment Works
Quick Review & A Bit New 5/44
x = 10y = x * x
x * x = y
x,y = y,x # a neat trick
![Page 13: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/13.jpg)
How Assignment Works
Quick Review & A Bit New 5/44
x = 10y = x * xx * x = y
x,y = y,x # a neat trick
![Page 14: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/14.jpg)
How Assignment Works
Quick Review & A Bit New 5/44
x = 10y = x * xx * x = y
x,y = y,x # a neat trick
![Page 15: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/15.jpg)
Warmup Quiz 6/44
Warmup Quiz
![Page 16: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/16.jpg)
Reminder
Warmup Quiz 7/44
You will have graded quiz starting from theupcoming Monday lecture!
![Page 17: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/17.jpg)
Our execution model
Warmup Quiz 8/44
![Page 18: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/18.jpg)
Question #1
Warmup Quiz 9/44
x = 10y = x + 1y = x * y
What is the value of y?A 11B 100C 110D None of the above
![Page 19: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/19.jpg)
Question #2
Warmup Quiz 10/44
x = 10y = x + 1y = x * y
What do we call x?A a literalB a variableC an expressionD a statement
![Page 20: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/20.jpg)
Question #3
Warmup Quiz 11/44
x = 10y = x + 1y = x * y
What do we call 10?A a literalB a variableC an expressionD a statement
![Page 21: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/21.jpg)
Question #2
Warmup Quiz 12/44
x = 10y = x + 1y = x * y
What do we call y = x * y?A a literalB a variableC an expressionD a statement
![Page 22: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/22.jpg)
Question #5
Warmup Quiz 13/44
x = 10y = xx = 5
What is the value of y?A 10B 5
![Page 23: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/23.jpg)
Data Types 14/44
Data Types
![Page 24: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/24.jpg)
What is an encoding?
Data Types 15/44
01001000 01000101 01001100 01001100What does a binary data value like this represent?
What does binary data represent?
How does the processor know?
![Page 25: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/25.jpg)
What is an encoding?
Data Types 15/44
01001000 01000101 01001100 01001100What does a binary data value like this represent?
What does binary data represent?How does the processor know?
![Page 26: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/26.jpg)
Our execution model
Data Types 16/44
![Page 27: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/27.jpg)
What is an encoding?
Data Types 17/44
01001000 01000101 01001100 01001100What does a binary data value like this represent?
What does binary data represent?How does the processor know?The encoding interprets the value.
![Page 28: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/28.jpg)
Our execution model
Data Types 18/44
![Page 29: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/29.jpg)
What is a data type?
Data Types 19/44
A data type defines an encoding rule.All values have a type.
The type defines how data is represented inmemory.The type defines allowed operations and how theywork.
![Page 30: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/30.jpg)
What is a data type?
Data Types 19/44
A data type defines an encoding rule.All values have a type.The type defines how data is represented inmemory.
The type defines allowed operations and how theywork.
![Page 31: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/31.jpg)
What is a data type?
Data Types 19/44
A data type defines an encoding rule.All values have a type.The type defines how data is represented inmemory.The type defines allowed operations and how theywork.
![Page 32: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/32.jpg)
Example
Data Types 20/44
01100111 can be the number 103, the letter g,hexadecimal 67, 3.5, etc.
So what are these data types?
![Page 33: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/33.jpg)
Numeric Data Types 21/44
Numeric Data Types
![Page 34: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/34.jpg)
How do binary numbers work?
Numeric Data Types 22/44
Numeric types can be represented in binary:000 0 100 4001 1 101 5010 2 110 6011 3 111 7
If we add more, the number overflows.Negative numbers? Add a sign bit.
![Page 35: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/35.jpg)
How do binary numbers work?
Numeric Data Types 22/44
Numeric types can be represented in binary:000 0 100 4001 1 101 5010 2 110 6011 3 111 7
If we add more, the number overflows.
Negative numbers? Add a sign bit.
![Page 36: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/36.jpg)
How do binary numbers work?
Numeric Data Types 22/44
Numeric types can be represented in binary:000 0 100 4001 1 101 5010 2 110 6011 3 111 7
If we add more, the number overflows.Negative numbers? Add a sign bit.
![Page 37: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/37.jpg)
Integers,Z
Numeric Data Types 23/44
Integers have been our only type thus far....,−4,−3,−2,−1, 0,+1,+2,+3, ...
What are limits?
![Page 38: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/38.jpg)
Integer operations
Numeric Data Types 24/44
Evaluating an expression of integers will generallyresult in an integer answer
3 + 5
EXCEPTION: DIVISION!3 / 4 → 0.753 // 4 → 0 (floor division)
![Page 39: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/39.jpg)
Integer operations
Numeric Data Types 24/44
Evaluating an expression of integers will generallyresult in an integer answer
3 + 5EXCEPTION: DIVISION!
3 / 4 → 0.753 // 4 → 0 (floor division)
![Page 40: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/40.jpg)
Integer operations
Numeric Data Types 24/44
Evaluating an expression of integers will generallyresult in an integer answer
3 + 5EXCEPTION: DIVISION!3 / 4 → 0.75
3 // 4 → 0 (floor division)
![Page 41: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/41.jpg)
Integer operations
Numeric Data Types 24/44
Evaluating an expression of integers will generallyresult in an integer answer
3 + 5EXCEPTION: DIVISION!3 / 4 → 0.753 // 4 → 0 (floor division)
![Page 42: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/42.jpg)
Floating-point numbers,R
Numeric Data Types 25/44
Floating-point numbers include a fractional part.
(Anything with a decimal point—2.4, 3.0.)What are limits?
Overflow/underflowArbitrary precision (π, e)
![Page 43: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/43.jpg)
Floating-point numbers,R
Numeric Data Types 25/44
Floating-point numbers include a fractional part.(Anything with a decimal point—2.4, 3.0.)
What are limits?Overflow/underflowArbitrary precision (π, e)
![Page 44: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/44.jpg)
Floating-point numbers,R
Numeric Data Types 25/44
Floating-point numbers include a fractional part.(Anything with a decimal point—2.4, 3.0.)What are limits?
Overflow/underflowArbitrary precision (π, e)
![Page 45: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/45.jpg)
Floating-point numbers,R
Numeric Data Types 25/44
Floating-point numbers include a fractional part.(Anything with a decimal point—2.4, 3.0.)What are limits?
Overflow/underflowArbitrary precision (π, e)
![Page 46: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/46.jpg)
Floating-point operations
Numeric Data Types 26/44
Evaluating an expression of floating-point valueswill result in a floating-point answer.
3.0 + 5.5 → 8.53.0 + 5.0 → 8.03 + 5.5 → ? (what happens here?)
Engineers and scientists need to think carefullyabout the precision of answers.
![Page 47: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/47.jpg)
Floating-point operations
Numeric Data Types 26/44
Evaluating an expression of floating-point valueswill result in a floating-point answer.
3.0 + 5.5 → 8.5
3.0 + 5.0 → 8.03 + 5.5 → ? (what happens here?)
Engineers and scientists need to think carefullyabout the precision of answers.
![Page 48: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/48.jpg)
Floating-point operations
Numeric Data Types 26/44
Evaluating an expression of floating-point valueswill result in a floating-point answer.
3.0 + 5.5 → 8.53.0 + 5.0 → 8.0
3 + 5.5 → ? (what happens here?)Engineers and scientists need to think carefullyabout the precision of answers.
![Page 49: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/49.jpg)
Floating-point operations
Numeric Data Types 26/44
Evaluating an expression of floating-point valueswill result in a floating-point answer.
3.0 + 5.5 → 8.53.0 + 5.0 → 8.03 + 5.5 → ? (what happens here?)
Engineers and scientists need to think carefullyabout the precision of answers.
![Page 50: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/50.jpg)
Floating-point operations
Numeric Data Types 26/44
Evaluating an expression of floating-point valueswill result in a floating-point answer.
3.0 + 5.5 → 8.53.0 + 5.0 → 8.03 + 5.5 → ? (what happens here?)
Engineers and scientists need to think carefullyabout the precision of answers.
![Page 51: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/51.jpg)
Complex numbers,C
Numeric Data Types 27/44
Represent numbers with an imaginary component.
Use j for i:1.0 + 1jThink of ”jmaginary” numbers, I suppose.
![Page 52: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/52.jpg)
Complex numbers,C
Numeric Data Types 27/44
Represent numbers with an imaginary component.Use j for i:1.0 + 1j
Think of ”jmaginary” numbers, I suppose.
![Page 53: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/53.jpg)
Complex numbers,C
Numeric Data Types 27/44
Represent numbers with an imaginary component.Use j for i:1.0 + 1jThink of ”jmaginary” numbers, I suppose.
![Page 54: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/54.jpg)
Example
Numeric Data Types 28/44
x = 4y = 3 + 1jz = 33.3333print( x + y + z )
What is printed to the screen?
A 40B 40.3333C 40.3333 + 1jD None of the above
![Page 55: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/55.jpg)
Example
Numeric Data Types 28/44
x = 4y = 3 + 1jz = 33.3333print( x + y + z )
What is printed to the screen?A 40B 40.3333C 40.3333 + 1jD None of the above
![Page 56: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/56.jpg)
Attribute operator .
Numeric Data Types 29/44
Reaches inside of a value to access part of itsdata (called an attribute).
Extracts special variables stored “inside” of thetype.print(x.real)print(x.imag)Both of these components are floats.
![Page 57: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/57.jpg)
Attribute operator .
Numeric Data Types 29/44
Reaches inside of a value to access part of itsdata (called an attribute).Extracts special variables stored “inside” of thetype.print(x.real)print(x.imag)
Both of these components are floats.
![Page 58: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/58.jpg)
Attribute operator .
Numeric Data Types 29/44
Reaches inside of a value to access part of itsdata (called an attribute).Extracts special variables stored “inside” of thetype.print(x.real)print(x.imag)Both of these components are floats.
![Page 59: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/59.jpg)
Example
Numeric Data Types 30/44
x = (3.5 + 1j)y = 1z = x + y
What is the value of z.imag?
A 4.5 + 1jB 4.5C 1jD 1.0
![Page 60: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/60.jpg)
Example
Numeric Data Types 30/44
x = (3.5 + 1j)y = 1z = x + y
What is the value of z.imag?A 4.5 + 1jB 4.5C 1jD 1.0
![Page 61: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/61.jpg)
String Data Type 31/44
String Data Type
![Page 62: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/62.jpg)
How does text work?
String Data Type 32/44
Each symbol is stored individually, one byte long:01001000 7201000101 6901001100 7601001100 7601001111 79
![Page 63: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/63.jpg)
ASCII encoding table
String Data Type 33/44
72 69 76 76 79 = H E L L O'HELLO'
![Page 64: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/64.jpg)
ASCII encoding table
String Data Type 33/44
72 69 76 76 79 = H E L L O
'HELLO'
![Page 65: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/65.jpg)
ASCII encoding table
String Data Type 33/44
72 69 76 76 79 = H E L L O'HELLO'
![Page 66: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/66.jpg)
Strings
String Data Type 34/44
As a literal: text surrounded by quotes."DEEP"
Each symbol is a character.Unlike numeric types, strings vary in length.
![Page 67: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/67.jpg)
Strings
String Data Type 34/44
As a literal: text surrounded by quotes."DEEP"
Each symbol is a character.
Unlike numeric types, strings vary in length.
![Page 68: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/68.jpg)
Strings
String Data Type 34/44
As a literal: text surrounded by quotes."DEEP"
Each symbol is a character.Unlike numeric types, strings vary in length.
![Page 69: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/69.jpg)
String operations
String Data Type 35/44
Concatenation: combine two stringsUses the + symbol'RACE' + 'CAR'
Repetition: repeat a stringUses the *'HELLO '*10
Formatting: used to encode other data as stringUses % symbol
![Page 70: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/70.jpg)
String operations
String Data Type 35/44
Concatenation: combine two stringsUses the + symbol'RACE' + 'CAR'
Repetition: repeat a stringUses the *'HELLO '*10
Formatting: used to encode other data as stringUses % symbol
![Page 71: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/71.jpg)
String operations
String Data Type 35/44
Concatenation: combine two stringsUses the + symbol'RACE' + 'CAR'
Repetition: repeat a stringUses the *'HELLO '*10
Formatting: used to encode other data as stringUses % symbol
![Page 72: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/72.jpg)
Formatting operator
String Data Type 36/44
Creates string with value inserted
Formats nicelyRequires indicator of type inside of string
x = 100 * 54s = "String is: %i" % xprint(s)
![Page 73: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/73.jpg)
Formatting operator
String Data Type 36/44
Creates string with value insertedFormats nicelyRequires indicator of type inside of string
x = 100 * 54s = "String is: %i" % xprint(s)
![Page 74: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/74.jpg)
Formatting operator
String Data Type 36/44
Creates string with value insertedFormats nicelyRequires indicator of type inside of string
x = 100 * 54s = "String is: %i" % xprint(s)
![Page 75: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/75.jpg)
Example
String Data Type 37/44
name = "Tao"grade = 2 / 3m1 = "Hello, %s!" % namem2 = "Your grade is: %f." % gradeprint(m1)print(m2)
Hello, Tao!Your grade is 0.66667.
![Page 76: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/76.jpg)
Example
String Data Type 37/44
name = "Tao"grade = 2 / 3m1 = "Hello, %s!" % namem2 = "Your grade is: %f." % gradeprint(m1)print(m2)
Hello, Tao!Your grade is 0.66667.
![Page 77: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/77.jpg)
Example
String Data Type 38/44
x = 3s = ("%i" % (x+1)) * x**(5%x)print(s)
What does this program print?A 333333333333B 444444444C 9999D %i%i%i%i%i
![Page 78: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/78.jpg)
Indexing operator
String Data Type 39/44
Extracts single character
a = "FIRE"a[0]The integer is the index.We count from zero!If negative, counts down from end.
![Page 79: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/79.jpg)
Indexing operator
String Data Type 39/44
Extracts single charactera = "FIRE"a[0]
The integer is the index.We count from zero!If negative, counts down from end.
![Page 80: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/80.jpg)
Indexing operator
String Data Type 39/44
Extracts single charactera = "FIRE"a[0]The integer is the index.
We count from zero!If negative, counts down from end.
![Page 81: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/81.jpg)
Indexing operator
String Data Type 39/44
Extracts single charactera = "FIRE"a[0]The integer is the index.We count from zero!
If negative, counts down from end.
![Page 82: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/82.jpg)
Indexing operator
String Data Type 39/44
Extracts single charactera = "FIRE"a[0]The integer is the index.We count from zero!If negative, counts down from end.
![Page 83: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/83.jpg)
Question
String Data Type 40/44
s = "ABCDE"i = 3x = s[i]
What is the value of x?A 'A'B 'B'C 'C'D 'D'E 'E'
![Page 84: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/84.jpg)
Question
String Data Type 41/44
s = "ABCDE"i = 25 % 3y = s[i]
What is the value of y?A 'A'B 'B'C 'C'D 'D'E 'E'
![Page 85: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/85.jpg)
Question
String Data Type 42/44
s = "ABCDE"i = (11 % 3) - 7z = s[i]
What is the value of z?A 'A'B 'B'C 'C'D 'D'E 'E'
![Page 86: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/86.jpg)
Reminders 43/44
Reminders
![Page 87: Python Basics! - data types, strings, indexing...Administrivia Administrivia 3/44 Lab #2 tomorrow Sunday. Where can you get help in this class? Blackboard forum Instructors in labs](https://reader033.vdocument.in/reader033/viewer/2022050208/5f5ad9582f81e3013b729b97/html5/thumbnails/87.jpg)
Reminders
Reminders 44/44
Lab #2 tomorrow Sunday.