SlideShare a Scribd company logo
Course Overview,
Python Basics
Lecture 1
About Your Instructors
Walker White Dietrich Geisler
• New instructor
§ Taught 1110 this summer
§ First time with a large class
• Will be back next week
8/22/22 Overview, Types & Expressions 2
• Director: GDIAC
§ Game Design @ Cornell
§ Game courses in Spring
• Teach CS 1110 in fall
We Are (Essentially) Full!
• Lecture times are somewhat flexible.
§ Technically have room for ~50 in each
§ We can use this to swap lectures
• Labs/sections at fire code capacity
§ We lost ACCEL labs last years
§ New classrooms are not as flexible
• But lots of drops; watch Student Center!
8/22/22 Overview, Types & Expressions 3
CS 1110 Fall 2022
• Outcomes:
§ Fluency in (Python) procedural programming
• Usage of assignments, conditionals, and loops
• Ability read and test programs from specifications
§ Competency in object-oriented programming
• Ability to recognize and use objects and classes
§ Knowledge of searching and sorting algorithms
• Knowledge of basics of vector computation
• Website:
§ www.cs.cornell.edu/courses/cs1110/2022fa/
4
8/22/22 Overview, Types & Expressions
Intro Programming Classes Compared
CS 1110: Python
• No prior programming
experience necessary
• No calculus
• Slight focus on
§ Software engineering
§ Application design
CS 1112: Matlab
• No prior programming
experience necessary
• One semester of calculus
• Slight focus on
§ Scientific computation
§ Engineering applications
5
8/22/22 Overview, Types & Expressions
But either course serves as
a pre-requisite to CS 2110
CS 1133: Short Course in Python
• 2-credit course in how to use Python
§ Material is roughly the first half of CS 1110
§ Most of the Python of 1110, but not theory
§ Two assignments; no exams
§ No experience required
• This is the only way to take Python S/U
§ CS 1110 is no longer offered S/U (in fall)
§ Best for students that just want Python
8/22/22 Overview, Types & Expressions 6
Why Programming in Python?
• Python is easier for beginners
§ A lot less to learn before you start “doing”
§ Designed with “rapid prototyping” in mind
• Python is more relevant to non-CS majors
§ NumPy and SciPy heavily used by scientists
• Python is a more modern language
§ Popular for web applications (e.g. Facebook apps)
§ Also applicable to mobile app development
8/22/22 Overview, Types & Expressions 7
Class Structure
• Lectures. Every Tuesday/Thursday
§ Not just slides; interactive demos almost every lecture
§ Because of enrollment, please stay with your section
§ Semi-Mandatory. 1% Participation grade from iClickers
• Section/labs. Phillips 318 or Hollister 401
§ Guided exercises with TAs and consultants helping out
• Meets Tuesday/Thursday or Wednesday/Friday
• Only Phillips 318 has computers (bring your laptop)
§ Contact Amy (ahf42@cornell.edu) for section conflicts
§ Mandatory. Missing more than 3 lowers your final grade
8
8/22/22 Overview, Types & Expressions
Class Structure
• Lectures. Every Tuesday/Thursday
§ Not just slides; interactive demos almost every lecture
§ Because of enrollment, please stay with your section
§ Semi-Mandatory. 1% Participation grade from iClickers
• Section/labs. Phillips 318 or Hollister 401
§ Guided exercises with TAs and consultants helping out
• Meets Tuesday/Thursday or Wednesday/Friday
• Only Phillips 318 has computers (bring your laptop)
§ Contact Amy (ahf42@cornell.edu) for section conflicts
§ Mandatory. Missing more than 2 lowers your final grade
9
8/22/22 Overview, Types & Expressions
All Labs will be use the online system.
But they are not intended to be “online”.
Is there a TextBook?
No
8/22/22 Overview, Types & Expressions 10
Is there a TextBook?
No
8/22/22 Overview, Types & Expressions 11
The asynchronous videos
are essentially the textbook
What Do I Need for this Class?
• Laptop Computer
§ Capable of running Python (no ChromeBooks!)
§ Minimum of 8Gb of RAM
• Python Installation
§ Will be using the latest Anaconda version
§ See instructions on website for how to install
• iClicker. Acquire by next Tuesday
§ Credit for answering – even if wrong
§ iClicker App for smartphone is not acceptable
8/22/22 Overview, Types & Expressions 12
What Do I Need for this Class?
• Laptop Computer
§ Capable of running Python (no ChromeBooks!)
§ Minimum of 8Gb of RAM
• Python Installation
§ Will be using the latest Anaconda version
§ See instructions on website for how to install
• iClicker. Acquire by next Tuesday
§ Credit for answering – even if wrong
§ iClicker App for smartphone is not acceptable
8/22/22 Overview, Types & Expressions 13
You can use computers
in Phillips 318 if needed.
What Do I Need for this Class?
• Laptop Computer
§ Capable of running Python (no ChromeBooks!)
§ Minimum of 8Gb of RAM
• Python Installation
§ Will be using the latest Anaconda version
§ See instructions on website for how to install
• iClicker. Acquire by next Tuesday
§ Credit for answering – even if wrong
§ iClicker App for smartphone is not acceptable
8/22/22 Overview, Types & Expressions 14
The only MUST purchase
This Course is OS Agnostic
8/22/22 Overview, Types & Expressions 15
Windows 10
macOS
Catalina
macOS 10.15 or higher
Do NOT Even THINK It!
8/22/22 Overview, Types & Expressions 16
Coming this October
Do NOT Even THINK It!
8/22/22 Overview, Types & Expressions 17
Coming this October
Things to Do Before Next Class
• Visit the course website:
§ www.cs.cornell.edu/courses/cs1110/2022fa/
§ This IS the course syllabus, updated regularly
• Read Get Started
§ Enroll in Ed Discussions
§ Register your iClicker online
§ Sign into CMS and complete Survey 0
§ Install Python and complete Lab 0
§ Take the academic integrity quiz
8/22/22 Overview, Types & Expressions 18
Things to Do Before Next Class
• Visit the course website:
§ www.cs.cornell.edu/courses/cs1110/2022fa/
§ This IS the course syllabus, updated regularly
• Read Get Started
§ Enroll in Ed Discussions
§ Register your iClicker online
§ Sign into CMS and complete Survey 0
§ Install Python and complete Lab 0
§ Take the academic integrity quiz
8/22/22 Overview, Types & Expressions 19
Will talk about this
more next class
Some Words About About Grades
• This class is not curved (in traditional sense)
§ Curve = competition with other students
§ This is about material, not your classmates
• The grades mean something
§ A: mastered material; can be a consultant
§ B: good at material; ready to take 2110
§ C: it is a bad idea to take 2110
§ D: where did you go?
§ F: were you ever here?
8/22/22 Overview, Types & Expressions 20
Some Words About About Grades
• But this is not a weed-out course
§ We know students have different backgrounds
§ Students can do well regardless of experience
• But you may have to work hard!
§ If no experience, budget 10-12 hours of homework a week
8/22/22 Overview, Types & Expressions 21
A B C D/F
All Students 40% 40% 18% 2%
Some Experience 37% 41% 20% 2%
No Experience 32% 42% 24% 2%
42%
28%
Some Words About About Grades
• But this is not a weed-out course
§ We know students have different backgrounds
§ Students can do well regardless of experience
• But you may have to work hard!
§ If no experience, budget 10-12 hours of homework a week
8/22/22 Overview, Types & Expressions 22
A B C D/F
All Students 40% 40% 18% 2%
Some Experience 37% 41% 20% 2%
No Experience 32% 42% 24% 2%
Freshmen, No Exp 37% 39% 24% 0%
42%
28%
Getting Started with Python
• Will use the “command line”
§ OS X/Linux: Terminal
§ Windows: PowerShell
§ Purpose of the first lab
• Once installed type “python”
§ Starts an interactive shell
§ Type commands at >>>
§ Responds to commands
• Use it like a calculator
§ Use to evaluate expressions
8/22/22 Overview, Types & Expressions 23
This class uses Python 3.9
The Basics
8/22/22 Overview, Types & Expressions 24
12.345
42
“Hello!”
integer
Values
Types
Expressions
float (real number)
string (of characters)
34 * (23 + 14)
"Hel" + "lo!"
1.0 / 3.0
Expressions and Values
8/22/22 Overview, Types & Expressions 25
• An expression represents something
§ Python evaluates it, turning it into a value
§ Similar to what a calculator does
• Examples:
>>> 2.2
2.2
>>> (3 * 7 + 1) * 0.1
2.2
Value
Expression
Value
Expression
(Literal)
(Complex)
• Think about + in Python:
>>> 1+2
3
>>> "Hello"+"World"
"HelloWorld"
• Why does + given different answers?
§ + is different on data of different types
§ This idea is fundamental to programming
What Are Types?
8/22/22 Overview, Types & Expressions 26
adds numerically
glues together
A type is both
•a set of values, and
•the operations on them
What Are Types?
8/22/22 Overview, Types & Expressions 27
Example: int
• Values: integers
§ …, –1, 0, 1, …
§ Literals are just digits:
1, 45, 43028030
§ No commas or periods
• Operations: math!
§ +, – (add, subtract)
§ *, // (mult, divide)
§ ** (power-of)
8/22/22 Overview, Types & Expressions 28
Example: int
• Values: integers
§ …, –1, 0, 1, …
§ Literals are just digits:
1, 45, 43028030
§ No commas or periods
• Operations: math!
§ +, – (add, subtract)
§ *, // (mult, divide)
§ ** (power-of)
• Important Rule:
§ int ops make ints
§ (if making numbers)
• What about division?
§ 1 // 2 rounds to 0
§ / is not an int op
• Companion op: %
§ Gives the remainder
§ 7 % 3 evaluates to 1
8/22/22 Overview, Types & Expressions 29
Example: float
• Values: real numbers
§ 2.51, -0.56, 3.14159
§ Must have decimal
§ 2 is int, 2.0 is float
• Operations: math!
§ +, – (add, subtract)
§ *, / (mult, divide)
§ ** (power-of)
• Ops similar to int
• Division is different
§ Notice /, not //
§ 1.0/2.0 evals to 0.5
• But includes //, %
§ 5.4//2.2 evals to 2.0
§ 5.4 % 2.2 evals to 1.0
• Superset of int?
8/22/22 Overview, Types & Expressions 30
float values Have Finite Precision
• Try this example:
>>> 0.1+0.2
0.30000000000000004
• The problem is representation error
§ Not all fractions can be represented as (finite) decimals
§ Example: calculators represent 2/3 as 0.666667
• Python does not use decimals
§ It uses IEEE 754 standard (beyond scope of course)
§ Not all decimals can be represented in this standard
§ So Python picks something close enough
8/22/22 Overview, Types & Expressions 31
float values Have Finite Precision
• Try this example:
>>> 0.1+0.2
0.30000000000000004
• The problem is representation error
§ Not all fractions can be represented as (finite) decimals
§ Example: calculators represent 2/3 as 0.666667
• Python does not use decimals
§ It uses IEEE 754 standard (beyond scope of course)
§ Not all decimals can be represented in this standard
§ So Python picks something close enough
Expressions vs Values
8/22/22 Overview, Types & Expressions 32
int versus float
• This is why Python has two number types
§ int is limited, but the answers are always exact
§ float is flexible, but answers are approximate
• Errors in float expressions can propagate
§ Each operation adds more and more error
§ Small enough not to matter day-to-day
§ But important in scientific or graphics apps
(high precision is necessary)
§ Must think in terms of significant digits
8/22/22 Overview, Types & Expressions 33
Using Big float Numbers
• Exponent notation is useful for large (or small) values
§ –22.51e6 is –22.51 * 106 or –22510000
§ 22.51e–6 is 22.51 * 10–6 or 0.00002251
• Python prefers this in some cases
>>> 0.00000000001
1e-11
A second kind
of float literal
Remember: values
look like literals
8/22/22 Overview, Types & Expressions 34
Example: bool
• Values: True, False
§ That is it.
§ Must be capitalized!
• Three Operations
§ b and c
(True if both True)
§ b or c
(True if at least one is)
§ not b
(True if b is not)
• Made by comparisons
§ int, float operations
§ But produce a bool
• Order comparisons:
§ i < j, i <= j
§ i >= j, i > j
• Equality, inequality:
§ i == j (not = )
§ i != j
8/22/22 Overview, Types & Expressions 35
Example: str
• Values: text, or sequence of characters
§ String literals must be in quotes
§ Double quotes: "Hello World!", " abcex3$g<&"
§ Single quotes: 'Hello World!', ' abcex3$g<&’
• Operation: + (catenation, or concatenation)
§ 'ab' + 'cd' evaluates to 'abcd’
§ concatenation can only apply to strings
§ 'ab' + 2 produces an error
8/22/22 Overview, Types & Expressions 36

More Related Content

PDF
Workshop on python
PPT
Introduction to Python For Diploma Students
PPT
Python programming
PDF
Dead Simple Python Idiomatic Python for the Impatient Programmer Jason C. Mcd...
PPT
iNTRODUCATION TO PYTHON IN PROGRAMMING LANGUAGE
PPTX
Python PPT.pptx
PDF
Dead Simple Python Idiomatic Python for the Impatient Programmer Jason C. Mcd...
PDF
Python for Scientific Computing
Workshop on python
Introduction to Python For Diploma Students
Python programming
Dead Simple Python Idiomatic Python for the Impatient Programmer Jason C. Mcd...
iNTRODUCATION TO PYTHON IN PROGRAMMING LANGUAGE
Python PPT.pptx
Dead Simple Python Idiomatic Python for the Impatient Programmer Jason C. Mcd...
Python for Scientific Computing

Similar to Course Overview Python Basics Course Slides (20)

PDF
MIT6_0001F16_Lec1.pdf
PPT
Python_intro.ppt
PPT
introduction to python in english presentation file
PPTX
Python introduction towards data science
PPTX
Python programming language presentation
PPTX
python ppt
PPTX
Python4HPC.pptx
PPTX
Introduction to python programming ( part-1)
PDF
Fluent Python Clear Concise And Effective Programming 2nd Edition 2nd Luciano...
PPTX
Python4HPC.pptx
PDF
Luciano Ramalho - Fluent Python_ Clear, Concise, and Effective Programming-O'...
PPTX
4_Introduction to Python Programming.pptx
PDF
What is Python? (Silicon Valley CodeCamp 2015)
PDF
bv-python-einfuehrung aplication learn.pdf
PDF
LearningPython.pdf
PDF
Python basics
PDF
Python basics
PPTX
Lacture 1- Programming using python.pptx
PDF
05 python.pdf
PDF
Learning_Python.pdf
MIT6_0001F16_Lec1.pdf
Python_intro.ppt
introduction to python in english presentation file
Python introduction towards data science
Python programming language presentation
python ppt
Python4HPC.pptx
Introduction to python programming ( part-1)
Fluent Python Clear Concise And Effective Programming 2nd Edition 2nd Luciano...
Python4HPC.pptx
Luciano Ramalho - Fluent Python_ Clear, Concise, and Effective Programming-O'...
4_Introduction to Python Programming.pptx
What is Python? (Silicon Valley CodeCamp 2015)
bv-python-einfuehrung aplication learn.pdf
LearningPython.pdf
Python basics
Python basics
Lacture 1- Programming using python.pptx
05 python.pdf
Learning_Python.pdf
Ad

More from MuhammadIfitikhar (10)

PPTX
Lecture-00: Azure IoT Pi Day Slides.pptx
PPTX
Lecture-6: Azure and Iot hub lecture.pptx
PDF
Python course slides topic objects in python
PDF
Python Lecture slides topic Algorithm design
PDF
Python Slides conditioanls and control flow
PDF
Python course lecture slides specifications and testing
PDF
Python Lecture Slides topic strings handling
PDF
Python Course Lecture Defining Functions
PDF
Python Course Functions and Modules Slides
PDF
Python Lecture Slides Variables and Assignments
Lecture-00: Azure IoT Pi Day Slides.pptx
Lecture-6: Azure and Iot hub lecture.pptx
Python course slides topic objects in python
Python Lecture slides topic Algorithm design
Python Slides conditioanls and control flow
Python course lecture slides specifications and testing
Python Lecture Slides topic strings handling
Python Course Lecture Defining Functions
Python Course Functions and Modules Slides
Python Lecture Slides Variables and Assignments
Ad

Recently uploaded (20)

PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
System and Network Administraation Chapter 3
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
history of c programming in notes for students .pptx
PPTX
assetexplorer- product-overview - presentation
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
Introduction to Artificial Intelligence
PPTX
Computer Software and OS of computer science of grade 11.pptx
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
System and Network Administraation Chapter 3
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
history of c programming in notes for students .pptx
assetexplorer- product-overview - presentation
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Reimagine Home Health with the Power of Agentic AI​
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Upgrade and Innovation Strategies for SAP ERP Customers
Wondershare Filmora 15 Crack With Activation Key [2025
Design an Analysis of Algorithms I-SECS-1021-03
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
2025 Textile ERP Trends: SAP, Odoo & Oracle
Introduction to Artificial Intelligence
Computer Software and OS of computer science of grade 11.pptx
How to Migrate SBCGlobal Email to Yahoo Easily
PTS Company Brochure 2025 (1).pdf.......
Operating system designcfffgfgggggggvggggggggg
wealthsignaloriginal-com-DS-text-... (1).pdf
Embracing Complexity in Serverless! GOTO Serverless Bengaluru

Course Overview Python Basics Course Slides

  • 2. About Your Instructors Walker White Dietrich Geisler • New instructor § Taught 1110 this summer § First time with a large class • Will be back next week 8/22/22 Overview, Types & Expressions 2 • Director: GDIAC § Game Design @ Cornell § Game courses in Spring • Teach CS 1110 in fall
  • 3. We Are (Essentially) Full! • Lecture times are somewhat flexible. § Technically have room for ~50 in each § We can use this to swap lectures • Labs/sections at fire code capacity § We lost ACCEL labs last years § New classrooms are not as flexible • But lots of drops; watch Student Center! 8/22/22 Overview, Types & Expressions 3
  • 4. CS 1110 Fall 2022 • Outcomes: § Fluency in (Python) procedural programming • Usage of assignments, conditionals, and loops • Ability read and test programs from specifications § Competency in object-oriented programming • Ability to recognize and use objects and classes § Knowledge of searching and sorting algorithms • Knowledge of basics of vector computation • Website: § www.cs.cornell.edu/courses/cs1110/2022fa/ 4 8/22/22 Overview, Types & Expressions
  • 5. Intro Programming Classes Compared CS 1110: Python • No prior programming experience necessary • No calculus • Slight focus on § Software engineering § Application design CS 1112: Matlab • No prior programming experience necessary • One semester of calculus • Slight focus on § Scientific computation § Engineering applications 5 8/22/22 Overview, Types & Expressions But either course serves as a pre-requisite to CS 2110
  • 6. CS 1133: Short Course in Python • 2-credit course in how to use Python § Material is roughly the first half of CS 1110 § Most of the Python of 1110, but not theory § Two assignments; no exams § No experience required • This is the only way to take Python S/U § CS 1110 is no longer offered S/U (in fall) § Best for students that just want Python 8/22/22 Overview, Types & Expressions 6
  • 7. Why Programming in Python? • Python is easier for beginners § A lot less to learn before you start “doing” § Designed with “rapid prototyping” in mind • Python is more relevant to non-CS majors § NumPy and SciPy heavily used by scientists • Python is a more modern language § Popular for web applications (e.g. Facebook apps) § Also applicable to mobile app development 8/22/22 Overview, Types & Expressions 7
  • 8. Class Structure • Lectures. Every Tuesday/Thursday § Not just slides; interactive demos almost every lecture § Because of enrollment, please stay with your section § Semi-Mandatory. 1% Participation grade from iClickers • Section/labs. Phillips 318 or Hollister 401 § Guided exercises with TAs and consultants helping out • Meets Tuesday/Thursday or Wednesday/Friday • Only Phillips 318 has computers (bring your laptop) § Contact Amy (ahf42@cornell.edu) for section conflicts § Mandatory. Missing more than 3 lowers your final grade 8 8/22/22 Overview, Types & Expressions
  • 9. Class Structure • Lectures. Every Tuesday/Thursday § Not just slides; interactive demos almost every lecture § Because of enrollment, please stay with your section § Semi-Mandatory. 1% Participation grade from iClickers • Section/labs. Phillips 318 or Hollister 401 § Guided exercises with TAs and consultants helping out • Meets Tuesday/Thursday or Wednesday/Friday • Only Phillips 318 has computers (bring your laptop) § Contact Amy (ahf42@cornell.edu) for section conflicts § Mandatory. Missing more than 2 lowers your final grade 9 8/22/22 Overview, Types & Expressions All Labs will be use the online system. But they are not intended to be “online”.
  • 10. Is there a TextBook? No 8/22/22 Overview, Types & Expressions 10
  • 11. Is there a TextBook? No 8/22/22 Overview, Types & Expressions 11 The asynchronous videos are essentially the textbook
  • 12. What Do I Need for this Class? • Laptop Computer § Capable of running Python (no ChromeBooks!) § Minimum of 8Gb of RAM • Python Installation § Will be using the latest Anaconda version § See instructions on website for how to install • iClicker. Acquire by next Tuesday § Credit for answering – even if wrong § iClicker App for smartphone is not acceptable 8/22/22 Overview, Types & Expressions 12
  • 13. What Do I Need for this Class? • Laptop Computer § Capable of running Python (no ChromeBooks!) § Minimum of 8Gb of RAM • Python Installation § Will be using the latest Anaconda version § See instructions on website for how to install • iClicker. Acquire by next Tuesday § Credit for answering – even if wrong § iClicker App for smartphone is not acceptable 8/22/22 Overview, Types & Expressions 13 You can use computers in Phillips 318 if needed.
  • 14. What Do I Need for this Class? • Laptop Computer § Capable of running Python (no ChromeBooks!) § Minimum of 8Gb of RAM • Python Installation § Will be using the latest Anaconda version § See instructions on website for how to install • iClicker. Acquire by next Tuesday § Credit for answering – even if wrong § iClicker App for smartphone is not acceptable 8/22/22 Overview, Types & Expressions 14 The only MUST purchase
  • 15. This Course is OS Agnostic 8/22/22 Overview, Types & Expressions 15 Windows 10 macOS Catalina macOS 10.15 or higher
  • 16. Do NOT Even THINK It! 8/22/22 Overview, Types & Expressions 16 Coming this October
  • 17. Do NOT Even THINK It! 8/22/22 Overview, Types & Expressions 17 Coming this October
  • 18. Things to Do Before Next Class • Visit the course website: § www.cs.cornell.edu/courses/cs1110/2022fa/ § This IS the course syllabus, updated regularly • Read Get Started § Enroll in Ed Discussions § Register your iClicker online § Sign into CMS and complete Survey 0 § Install Python and complete Lab 0 § Take the academic integrity quiz 8/22/22 Overview, Types & Expressions 18
  • 19. Things to Do Before Next Class • Visit the course website: § www.cs.cornell.edu/courses/cs1110/2022fa/ § This IS the course syllabus, updated regularly • Read Get Started § Enroll in Ed Discussions § Register your iClicker online § Sign into CMS and complete Survey 0 § Install Python and complete Lab 0 § Take the academic integrity quiz 8/22/22 Overview, Types & Expressions 19 Will talk about this more next class
  • 20. Some Words About About Grades • This class is not curved (in traditional sense) § Curve = competition with other students § This is about material, not your classmates • The grades mean something § A: mastered material; can be a consultant § B: good at material; ready to take 2110 § C: it is a bad idea to take 2110 § D: where did you go? § F: were you ever here? 8/22/22 Overview, Types & Expressions 20
  • 21. Some Words About About Grades • But this is not a weed-out course § We know students have different backgrounds § Students can do well regardless of experience • But you may have to work hard! § If no experience, budget 10-12 hours of homework a week 8/22/22 Overview, Types & Expressions 21 A B C D/F All Students 40% 40% 18% 2% Some Experience 37% 41% 20% 2% No Experience 32% 42% 24% 2% 42% 28%
  • 22. Some Words About About Grades • But this is not a weed-out course § We know students have different backgrounds § Students can do well regardless of experience • But you may have to work hard! § If no experience, budget 10-12 hours of homework a week 8/22/22 Overview, Types & Expressions 22 A B C D/F All Students 40% 40% 18% 2% Some Experience 37% 41% 20% 2% No Experience 32% 42% 24% 2% Freshmen, No Exp 37% 39% 24% 0% 42% 28%
  • 23. Getting Started with Python • Will use the “command line” § OS X/Linux: Terminal § Windows: PowerShell § Purpose of the first lab • Once installed type “python” § Starts an interactive shell § Type commands at >>> § Responds to commands • Use it like a calculator § Use to evaluate expressions 8/22/22 Overview, Types & Expressions 23 This class uses Python 3.9
  • 24. The Basics 8/22/22 Overview, Types & Expressions 24 12.345 42 “Hello!” integer Values Types Expressions float (real number) string (of characters) 34 * (23 + 14) "Hel" + "lo!" 1.0 / 3.0
  • 25. Expressions and Values 8/22/22 Overview, Types & Expressions 25 • An expression represents something § Python evaluates it, turning it into a value § Similar to what a calculator does • Examples: >>> 2.2 2.2 >>> (3 * 7 + 1) * 0.1 2.2 Value Expression Value Expression (Literal) (Complex)
  • 26. • Think about + in Python: >>> 1+2 3 >>> "Hello"+"World" "HelloWorld" • Why does + given different answers? § + is different on data of different types § This idea is fundamental to programming What Are Types? 8/22/22 Overview, Types & Expressions 26 adds numerically glues together
  • 27. A type is both •a set of values, and •the operations on them What Are Types? 8/22/22 Overview, Types & Expressions 27
  • 28. Example: int • Values: integers § …, –1, 0, 1, … § Literals are just digits: 1, 45, 43028030 § No commas or periods • Operations: math! § +, – (add, subtract) § *, // (mult, divide) § ** (power-of) 8/22/22 Overview, Types & Expressions 28
  • 29. Example: int • Values: integers § …, –1, 0, 1, … § Literals are just digits: 1, 45, 43028030 § No commas or periods • Operations: math! § +, – (add, subtract) § *, // (mult, divide) § ** (power-of) • Important Rule: § int ops make ints § (if making numbers) • What about division? § 1 // 2 rounds to 0 § / is not an int op • Companion op: % § Gives the remainder § 7 % 3 evaluates to 1 8/22/22 Overview, Types & Expressions 29
  • 30. Example: float • Values: real numbers § 2.51, -0.56, 3.14159 § Must have decimal § 2 is int, 2.0 is float • Operations: math! § +, – (add, subtract) § *, / (mult, divide) § ** (power-of) • Ops similar to int • Division is different § Notice /, not // § 1.0/2.0 evals to 0.5 • But includes //, % § 5.4//2.2 evals to 2.0 § 5.4 % 2.2 evals to 1.0 • Superset of int? 8/22/22 Overview, Types & Expressions 30
  • 31. float values Have Finite Precision • Try this example: >>> 0.1+0.2 0.30000000000000004 • The problem is representation error § Not all fractions can be represented as (finite) decimals § Example: calculators represent 2/3 as 0.666667 • Python does not use decimals § It uses IEEE 754 standard (beyond scope of course) § Not all decimals can be represented in this standard § So Python picks something close enough 8/22/22 Overview, Types & Expressions 31
  • 32. float values Have Finite Precision • Try this example: >>> 0.1+0.2 0.30000000000000004 • The problem is representation error § Not all fractions can be represented as (finite) decimals § Example: calculators represent 2/3 as 0.666667 • Python does not use decimals § It uses IEEE 754 standard (beyond scope of course) § Not all decimals can be represented in this standard § So Python picks something close enough Expressions vs Values 8/22/22 Overview, Types & Expressions 32
  • 33. int versus float • This is why Python has two number types § int is limited, but the answers are always exact § float is flexible, but answers are approximate • Errors in float expressions can propagate § Each operation adds more and more error § Small enough not to matter day-to-day § But important in scientific or graphics apps (high precision is necessary) § Must think in terms of significant digits 8/22/22 Overview, Types & Expressions 33
  • 34. Using Big float Numbers • Exponent notation is useful for large (or small) values § –22.51e6 is –22.51 * 106 or –22510000 § 22.51e–6 is 22.51 * 10–6 or 0.00002251 • Python prefers this in some cases >>> 0.00000000001 1e-11 A second kind of float literal Remember: values look like literals 8/22/22 Overview, Types & Expressions 34
  • 35. Example: bool • Values: True, False § That is it. § Must be capitalized! • Three Operations § b and c (True if both True) § b or c (True if at least one is) § not b (True if b is not) • Made by comparisons § int, float operations § But produce a bool • Order comparisons: § i < j, i <= j § i >= j, i > j • Equality, inequality: § i == j (not = ) § i != j 8/22/22 Overview, Types & Expressions 35
  • 36. Example: str • Values: text, or sequence of characters § String literals must be in quotes § Double quotes: "Hello World!", " abcex3$g<&" § Single quotes: 'Hello World!', ' abcex3$g<&’ • Operation: + (catenation, or concatenation) § 'ab' + 'cd' evaluates to 'abcd’ § concatenation can only apply to strings § 'ab' + 2 produces an error 8/22/22 Overview, Types & Expressions 36