The document provides an overview of Unit 1 of a Python programming course taught by Dr. C. Sreedhar. Unit 1 covers introduction to Python including its history, installation, execution, commenting, data types, operators, and writing simple programs. It discusses Python's character set, tokens, core data types, I/O functions, assigning values to variables, and multiple assignments. Operators and expressions such as arithmetic, comparison, logical, and bitwise operators are also covered. Examples of simple Python programs are provided.
First in the series of slides for python programming, covering topics like programming language, python programming constructs, loops and control statements.
Chapter 2 Input,Processing and Output.pdflaila287141
This chapter discusses program design and the input/output process. It covers designing programs through pseudocode, flowcharts and algorithms. The chapter then explains how programs take in input, perform processing, and output results. It discusses printing output, using variables, reading keyboard input, performing calculations, and formatting output display. The chapter emphasizes designing programs before writing code.
The document discusses Python programming fundamentals including tokens, literals, variables, statements, expressions, and assignments. Key points covered include:
- Tokens are the smallest units of a Python program and include literals, identifiers, keywords, and operators.
- Literals represent fixed values like strings, numbers, Booleans, and collections.
- Variables store values that can change, while literals represent fixed values. Variables are assigned values using statements.
- Expressions combine values using operators to produce new values. Assignment statements allow values to be stored in variables.
This document provides an overview of key concepts for data science in Python, including popular Python packages like NumPy and Pandas. It introduces Python basics like data types, operators, and functions. It then covers NumPy topics such as arrays, slicing, splitting and reshaping arrays. It discusses Pandas Series and DataFrame data structures. Finally, it covers operations on missing data and combining datasets using merge and join functions.
The document provides an overview of a Python programming course taught by Dr. C. Sreedhar. The course covers topics like the history of Python, installing Python, data types, operators, expressions, functions, and more. It includes code examples for basic programs to calculate area and perimeter, check if a number is even or odd, and determine if a number is divisible by 4 and 9. The document contains lecture slides with explanations and syntax for various Python concepts.
2_Data Representation and Expressions (1).pptxbrsudhakar9
This document discusses datatypes and their components. It explains that a datatype consists of a set of values and a set of operations that can be performed on those values. It provides examples of different datatypes like boolean, integer, and structured datatypes. The document also discusses literals, which are direct representations of data values like numeric literals, string literals, and character representation in encodings. It then covers variables and identifiers, explaining that variables associate names with values in memory. Key concepts discussed include assignment, variable identifiers, and keyword identifiers. The document also discusses operators that represent operations on operands of a datatype and expressions that combine operators and operands to evaluate to a value. It explains operator precedence and associativity rules. Finally, it touches on
This document provides an introduction and overview of the Python programming language. It describes Python as a general-purpose, object-oriented programming language with features like high-level programming capabilities, an easily understandable syntax, portability, and being easy to learn. It then discusses Python's characteristics like being an interpreted language, supporting object-oriented programming, being interactive and easy to use, having straightforward syntax, being portable, extendable, and scalable. The document also outlines some common uses of Python like for creating web and desktop applications, and provides examples of using Python's interactive and script modes.
The document provides an overview of the Python programming language. It discusses the programming cycle in Python, interacting with Python programs using input/output, basic Python types like integers and strings, operators, variables and assignments, conditional statements like if/else, loops like while and for, and functions. It also notes some cautions around using floats for comparisons due to representation approximations.
This document outlines the objectives, outcomes, syllabus, and content of a Python Programming course. The objectives are to learn Python syntax, semantics, data types, containers, control flow, functions, object-oriented programming, and coding techniques. The outcomes are developing programming skills in Python concepts like data types, applying Python basics to solve coding tasks involving conditionals, loops, and object-oriented programming. The syllabus covers introduction to Python, control structures, strings/files, lists/dictionaries, functions, file operations, errors/exceptions, and graphical user interfaces.
The document discusses Python programming language. It provides an overview of what Python is, what it can be used for, and why it is a popular language. Specifically, it notes that Python was created by Guido van Rossum and released in 1991. It is used for web development, software development, mathematics, and system scripting. The document then covers Python syntax, basic data types, operators, decision making and control flow statements like if/else and loops.
This document provides a quick tour of the Python programming language. It introduces basic Python concepts like data types, variables, operators, conditional statements, loops, and functions. It explains how to get user input, perform type conversions, and work with common data types like integers, floats, strings, and booleans. It also demonstrates how to define functions, use default arguments and keyword arguments, and handle global variables. The document uses examples to illustrate concepts like arithmetic operations, string slicing, indexing, concatenation, and repetition.
This document provides an overview of Python programming concepts including:
- The Python programming cycle involves writing/editing code, running it, checking if it works, and repeating the process with more inputs if needed.
- Python has various built-in types like integers, floats, strings, and booleans that define values and operations on those values.
- Key concepts like variables, operators, expressions, conditional statements like if/else, and loops like while and for are introduced.
- Functions allow breaking programs into reusable pieces of code. Functions take inputs, perform operations, and return outputs.
The document provides an overview of the Python programming language. It discusses why Python is useful for students and professionals, its major features like being object-oriented and having a large standard library. The document also covers Python's history, how to install it and set the environment variables, basic syntax like variables and data types, operators, and common programming constructs like conditionals and loops.
This document provides an overview of key Python concepts including operators and expressions, data types, variables, functions, program flow, and input/output. It discusses operators like +, -, *, / and comparison operators. It explains that Python has different data types like integers, floats, booleans and strings. Variables are used to store and reference data. Functions allow for code reuse and modularization. Control structures like if statements allow programs to make decisions based on conditional logic.
The document provides information about the Python programming language. It discusses that Python is an interpreted, interactive, and object-oriented language well-suited for beginners. It provides details on Python's history and development as well as an overview of its core features like a broad standard library, portability, extensibility, support for databases, and an interactive mode. The document also describes how to get Python, run Python code through an interactive interpreter or script, and use integrated development environments. It covers basic programming concepts in Python like arithmetic, decision making with if/else statements, loops, lists, and functions.
This document provides an introduction to Python programming. It discusses the programming cycle of writing code, running it, checking if it works, and iterating if needed. It also covers Python programming basics like data types, variables, operators, expressions, conditional statements like if/else, and loops. Examples are provided throughout to illustrate concepts like input, type conversion, arithmetic operations, and printing multiplication tables using a while loop. The document is intended to teach Python programming fundamentals to new learners.
2_Data Representation and Expressions (1).pptxbrsudhakar9
This document discusses datatypes and their components. It explains that a datatype consists of a set of values and a set of operations that can be performed on those values. It provides examples of different datatypes like boolean, integer, and structured datatypes. The document also discusses literals, which are direct representations of data values like numeric literals, string literals, and character representation in encodings. It then covers variables and identifiers, explaining that variables associate names with values in memory. Key concepts discussed include assignment, variable identifiers, and keyword identifiers. The document also discusses operators that represent operations on operands of a datatype and expressions that combine operators and operands to evaluate to a value. It explains operator precedence and associativity rules. Finally, it touches on
This document provides an introduction and overview of the Python programming language. It describes Python as a general-purpose, object-oriented programming language with features like high-level programming capabilities, an easily understandable syntax, portability, and being easy to learn. It then discusses Python's characteristics like being an interpreted language, supporting object-oriented programming, being interactive and easy to use, having straightforward syntax, being portable, extendable, and scalable. The document also outlines some common uses of Python like for creating web and desktop applications, and provides examples of using Python's interactive and script modes.
The document provides an overview of the Python programming language. It discusses the programming cycle in Python, interacting with Python programs using input/output, basic Python types like integers and strings, operators, variables and assignments, conditional statements like if/else, loops like while and for, and functions. It also notes some cautions around using floats for comparisons due to representation approximations.
This document outlines the objectives, outcomes, syllabus, and content of a Python Programming course. The objectives are to learn Python syntax, semantics, data types, containers, control flow, functions, object-oriented programming, and coding techniques. The outcomes are developing programming skills in Python concepts like data types, applying Python basics to solve coding tasks involving conditionals, loops, and object-oriented programming. The syllabus covers introduction to Python, control structures, strings/files, lists/dictionaries, functions, file operations, errors/exceptions, and graphical user interfaces.
The document discusses Python programming language. It provides an overview of what Python is, what it can be used for, and why it is a popular language. Specifically, it notes that Python was created by Guido van Rossum and released in 1991. It is used for web development, software development, mathematics, and system scripting. The document then covers Python syntax, basic data types, operators, decision making and control flow statements like if/else and loops.
This document provides a quick tour of the Python programming language. It introduces basic Python concepts like data types, variables, operators, conditional statements, loops, and functions. It explains how to get user input, perform type conversions, and work with common data types like integers, floats, strings, and booleans. It also demonstrates how to define functions, use default arguments and keyword arguments, and handle global variables. The document uses examples to illustrate concepts like arithmetic operations, string slicing, indexing, concatenation, and repetition.
This document provides an overview of Python programming concepts including:
- The Python programming cycle involves writing/editing code, running it, checking if it works, and repeating the process with more inputs if needed.
- Python has various built-in types like integers, floats, strings, and booleans that define values and operations on those values.
- Key concepts like variables, operators, expressions, conditional statements like if/else, and loops like while and for are introduced.
- Functions allow breaking programs into reusable pieces of code. Functions take inputs, perform operations, and return outputs.
The document provides an overview of the Python programming language. It discusses why Python is useful for students and professionals, its major features like being object-oriented and having a large standard library. The document also covers Python's history, how to install it and set the environment variables, basic syntax like variables and data types, operators, and common programming constructs like conditionals and loops.
This document provides an overview of key Python concepts including operators and expressions, data types, variables, functions, program flow, and input/output. It discusses operators like +, -, *, / and comparison operators. It explains that Python has different data types like integers, floats, booleans and strings. Variables are used to store and reference data. Functions allow for code reuse and modularization. Control structures like if statements allow programs to make decisions based on conditional logic.
The document provides information about the Python programming language. It discusses that Python is an interpreted, interactive, and object-oriented language well-suited for beginners. It provides details on Python's history and development as well as an overview of its core features like a broad standard library, portability, extensibility, support for databases, and an interactive mode. The document also describes how to get Python, run Python code through an interactive interpreter or script, and use integrated development environments. It covers basic programming concepts in Python like arithmetic, decision making with if/else statements, loops, lists, and functions.
This document provides an introduction to Python programming. It discusses the programming cycle of writing code, running it, checking if it works, and iterating if needed. It also covers Python programming basics like data types, variables, operators, expressions, conditional statements like if/else, and loops. Examples are provided throughout to illustrate concepts like input, type conversion, arithmetic operations, and printing multiplication tables using a while loop. The document is intended to teach Python programming fundamentals to new learners.
Insurance policy management software transforms complex, manual insurance operations into streamlined, efficient digital workflows, enhancing productivity, accuracy, customer service, and profitability for insurers. Visit https://www.damcogroup.com/insurance/policy-management-software for more details!
Zoneranker’s Digital marketing solutionsreenashriee
Zoneranker offers expert digital marketing services tailored for businesses in Theni. From SEO and PPC to social media and content marketing, we help you grow online. Partner with us to boost visibility, leads, and sales.
AI and Deep Learning with NVIDIA TechnologiesSandeepKS52
Artificial intelligence and deep learning are transforming various fields by enabling machines to learn from data and make decisions. Understanding how to prepare data effectively is crucial, as it lays the foundation for training models that can recognize patterns and improve over time. Once models are trained, the focus shifts to deployment, where these intelligent systems are integrated into real-world applications, allowing them to perform tasks and provide insights based on new information. This exploration of AI encompasses the entire process from initial concepts to practical implementation, highlighting the importance of each stage in creating effective and reliable AI solutions.
Advanced Token Development - Decentralized Innovationarohisinghas720
The world of blockchain is evolving at a fast pace, and at the heart of this transformation lies advanced token development. No longer limited to simple digital assets, today’s tokens are programmable, dynamic, and play a crucial role in driving decentralized applications across finance, governance, gaming, and beyond.
Plooma is a writing platform to plan, write, and shape books your wayPlooma
Plooma is your all in one writing companion, designed to support authors at every twist and turn of the book creation journey. Whether you're sketching out your story's blueprint, breathing life into characters, or crafting chapters, Plooma provides a seamless space to organize all your ideas and materials without the overwhelm. Its intuitive interface makes building rich narratives and immersive worlds feel effortless.
Packed with powerful story and character organization tools, Plooma lets you track character development and manage world building details with ease. When it’s time to write, the distraction-free mode offers a clean, minimal environment to help you dive deep and write consistently. Plus, built-in editing tools catch grammar slips and style quirks in real-time, polishing your story so you don’t have to juggle multiple apps.
What really sets Plooma apart is its smart AI assistant - analyzing chapters for continuity, helping you generate character portraits, and flagging inconsistencies to keep your story tight and cohesive. This clever support saves you time and builds confidence, especially during those complex, detail packed projects.
Getting started is simple: outline your story’s structure and key characters with Plooma’s user-friendly planning tools, then write your chapters in the focused editor, using analytics to shape your words. Throughout your journey, Plooma’s AI offers helpful feedback and suggestions, guiding you toward a polished, well-crafted book ready to share with the world.
With Plooma by your side, you get a powerful toolkit that simplifies the creative process, boosts your productivity, and elevates your writing - making the path from idea to finished book smoother, more fun, and totally doable.
Get Started here: https://www.plooma.ink/
How the US Navy Approaches DevSecOps with Raise 2.0Anchore
Join us as Anchore's solutions architect reveals how the U.S. Navy successfully approaches the shift left philosophy to DevSecOps with the RAISE 2.0 Implementation Guide to support its Cyber Ready initiative. This session will showcase practical strategies for defense application teams to pivot from a time-intensive compliance checklist and mindset to continuous cyber-readiness with real-time visibility.
Learn how to break down organizational silos through RAISE 2.0 principles and build efficient, secure pipeline automation that produces the critical security artifacts needed for Authorization to Operate (ATO) approval across military environments.
Explore innovative tools tailored for modern finance with our Money Lender Software Development, efficient Daily Pigmy Collection Software, and streamlined Personal Loan Software. This presentation showcases how these solutions simplify loan management, boost collection efficiency, and enhance customer experience for NBFCs, microfinance firms, and individual lenders.
Integrating Survey123 and R&H Data Using FMESafe Software
West Virginia Department of Transportation (WVDOT) actively engages in several field data collection initiatives using Collector and Survey 123. A critical component for effective asset management and enhanced analytical capabilities is the integration of Geographic Information System (GIS) data with Linear Referencing System (LRS) data. Currently, RouteID and Measures are not captured in Survey 123. However, we can bridge this gap through FME Flow automation. When a survey is submitted through Survey 123 for ArcGIS Portal (10.8.1), it triggers FME Flow automation. This process uses a customized workbench that interacts with a modified version of Esri's Geometry to Measure API. The result is a JSON response that includes RouteID and Measures, which are then applied to the feature service record.
In this session we cover the benefits of a migration to Cosmos DB, migration paths, common pain points and best practices. We share our firsthand experiences and customer stories. Adiom is the trusted partner for migration solutions that enable seamless online database migrations from MongoDB to Cosmos DB vCore, and DynamoDB to Cosmos DB for NoSQL.
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...Natan Silnitsky
In a world where speed, resilience, and fault tolerance define success, Wix leverages Kafka to power asynchronous programming across 4,000 microservices. This talk explores four key patterns that boost developer velocity while solving common challenges with scalable, efficient, and reliable solutions:
1. Integration Events: Shift from synchronous calls to pre-fetching to reduce query latency and improve user experience.
2. Task Queue: Offload non-critical tasks like notifications to streamline request flows.
3. Task Scheduler: Enable precise, fault-tolerant delayed or recurring workflows with robust scheduling.
4. Iterator for Long-running Jobs: Process extensive workloads via chunked execution, optimizing scalability and resilience.
For each pattern, we’ll discuss benefits, challenges, and how we mitigate drawbacks to create practical solutions
This session offers actionable insights for developers and architects tackling distributed systems, helping refine microservices and adopting Kafka-driven async excellence.
AI-Powered Compliance Solutions for Global Regulations | Certivocertivoai
Certivo offers AI-powered compliance solutions designed to help businesses in the USA, EU, and UK simplify complex regulatory demands. From environmental and product compliance to safety, quality, and sustainability, our platform automates supplier documentation, manages certifications, and integrates with ERP/PLM systems. Ensure seamless RoHS, REACH, PFAS, and Prop 65 compliance through predictive insights and multilingual support. Turn compliance into a competitive edge with Certivo’s intelligent, scalable, and audit-ready platform.
A brief introduction to OpenTelemetry, with a practical example of auto-instrumenting a Java web application with the Grafana stack (Loki, Grafana, Tempo, and Mimir).
2. Announcements for Today
If Not Done Already
• Install Python
§ Make sure right version
§ Make sure Kivy works
• Register your iClicker
• Sign into CMS
§ Fill out the Survey
§ Complete AI Quiz
Lab 1
• Labs are due at next class
§ So lab 1 is due now
§ By end of the lab section
§ Try to finish them before
• Makes T/W a little tight
§ Only 2 days (not 5)
§ Will keep them small
• Getting behind is bad!
8/25/22 Variables & Assignments 2
3. Helping You Succeed in this Class
• Consultants. Phillips 318 (after hours)
§ Daily office hours (see website) with consultants
§ Very useful when working on assignments
• AEW Workshops. Additional discussion course
§ Runs parallel to this class – completely optional
§ See website; talk to advisors in Olin 167.
• Ed Discussions. Forum to ask and answer questions
§ Go here first before sending question in e-mail
• Office Hours. Talk to the professor!
§ Couches in Statler Balcony between classes
8/25/22 Variables & Assignments 3
4. Labs vs. Assignments
Labs
• Held twice a week
• Graded on completeness
§ Always S/U
§ Try again if not finished
• Indirect affect on grade
§ Can miss up to 3 labs
§ After that, grade reduced
• Similar to language drills
§ Simple, but take time
Assignments
• Every two weeks
§ First one due Sep. 16
• Graded on correctness
§ Assign points out of 100
• But first one is for mastery
§ Resubmit until perfect grade
• 40% of your final grade
• Can work with a partner!
§ Mixer coming soon
8/25/22 Variables & Assignments 4
5. Academic Integrity
• Every semester we have cases of plagiarism
§ Claiming the work of others as your own
§ This is an Academic Integrity violation
• This course has a very specific policy
§ Do not listen to (non-staff) upperclassmen
§ Look at the course website for the new details
• Complete Academic Integrity Quiz on CMS
§ Must complete successfully to stay in class
8/25/22 Variables & Assignments 5
6. iClickers
• Have you registered your iClicker?
• If not, visit (free service; no surcharge!)
§ https://cs1110.cs.cornell.edu/py/clicker
• See the course web page for more:
§ http://www.cs.cornell.edu/courses/cs1110/2022fa
§ Click “Materials/Textbook”
§ Look under “iClickers”
8/25/22 Variables & Assignments 6
7. Warm-Up: Using Python
• How do you plan to use Python?
A. I want to work mainly in the Phillips lab
B. I want to use my own Windows computer
C. I want to use my own Macintosh computer
D. I want to use my own Linux computer
E. I will use whatever I can get my hands on
8/25/22 Variables & Assignments 7
8. Type: Set of values and the operations on them
• Type int:
§ Values: integers
§ Ops: +, –, *, //, %, **
• Type float:
§ Values: real numbers
§ Ops: +, –, *, /, **
• Type bool:
§ Values: True and False
§ Ops: not, and, or
• Type str:
§ Values: string literals
• Double quotes: "abc"
• Single quotes: 'abc'
§ Ops: + (concatenation)
Will see more types
in a few weeks
8/25/22 Variables & Assignments 8
9. 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/25/22 Variables & Assignments 9
10. Converting Values Between Types
• Basic form: type(expression)
§ This is an expression
§ Evaluates to value, converted to new type
§ This is sometimes called casting
• Examples:
§ float(2) evaluates to 2.0 (a float)
§ int(2.6) evaluates to 2 (an int)
§ Note information loss in 2nd example
8/25/22 Variables & Assignments 10
11. Converting Values Between Types
• Conversion is measured narrow to wide
bool ⇒ int ⇒ float
• Widening: Convert to a wider type
§ Python does automatically
§ Example: 1/2.0 evaluates to 0.5
• Narrowing: Convert to a narrower type
§ Python never does automatically
§ Example: float(int(2.6)) evaluates to 2.0
8/25/22 Variables & Assignments 11
12. Operator Precedence
• What is the difference between these two?
§ 2*(1+3)
§ 2*1 + 3
8/25/22 Variables & Assignments 12
13. Operator Precedence
• What is the difference between these two?
§ 2*(1+3)
§ 2*1 + 3
• Operations are performed in a set order
§ Parentheses make the order explicit
§ What happens when no parentheses?
add, then multiply
multiply, then add
8/25/22 Variables & Assignments 13
14. Operator Precedence
• What is the difference between these two?
§ 2*(1+3)
§ 2*1 + 3
• Operations are performed in a set order
§ Parentheses make the order explicit
§ What happens when no parentheses?
add, then multiply
multiply, then add
8/25/22 Variables & Assignments 14
Operator Precedence:
The fixed order Python processes
operators in absence of parentheses
15. Precedence of Python Operators
• Exponentiation: **
• Unary operators: + –
• Binary arithmetic: * / %
• Binary arithmetic: + –
• Comparisons: < > <= >=
• Equality relations: == !=
• Logical not
• Logical and
• Logical or
• Precedence goes downwards
§ Parentheses highest
§ Logical ops lowest
• Same line = same precedence
§ Read “ties” left to right
§ Example: 1/2*3 is (1/2)*3
• There is a video about this
• See website for more info
• Was major portion of Lab 1
8/25/22 Variables & Assignments 15
16. Expressions vs Statements
Expression
• Represents something
§ Python evaluates it
§ End result is a value
• Examples:
§ 2.3
§ (3+5)/4
Statement
• Does something
§ Python executes it
§ Need not result in a value
• Examples:
§ print('Hello')
§ import sys
Will see later this is not a clear cut separation
Literal
Complex
8/25/22 Variables & Assignments 16
17. Variables
• A variable
§ is a box (memory location)
§ with a name
§ and a value in the box
• Examples:
5
x Variable x, with value 5 (of type int)
20.1
area Variable area, w/ value 20.1 (of type float)
8/25/22 Variables & Assignments 17
18. Using Variables
• Variables can be used in expressions
§ Evaluate to the value that is in the box
§ Example: 1 + x evaluates to 6
• Variables can change values
§ Example: 1 + x evaluates to 2.5
§ Can even change the type of their value
§ Different from other languages (e.g. Java)
5
x
5
x 1.5
x
8/25/22 Variables & Assignments 18
19. Naming Variables
• Python has strict rules of how to assign names
§ Names must only contain letters, numbers, _
§ They cannot start with a number
• Examples
§ e1 is a valid name
§ 1e2 is not valid (it is a float)
§ a_b is a valid name
§ a+b is not valid (it is + on two variables)
8/25/22 Variables & Assignments 19
20. Variables and Assignment Statements
• Variables are created by assignment statements
x = 5
• This is a statement, not an expression
§ Expression: Something Python turns into a value
§ Statement: Command for Python to do something
§ Difference is that has no value itself
• Example:
>>> x = 5
(NOTHING)
x
the value
the variable
5
But can now use x
as an expression
8/25/22 Variables & Assignments 20
21. Variables Do Not Exist Until Made
• Example:
>>> y
Error!
>>> y = 3
>>> y
3
• Changes our model of Python
§ Before we just typed in one line at a time
§ Now program is a sequence of lines
8/25/22 Variables & Assignments 21
22. Assignments May Contain Expressions
• Example: x = 1 + 2
§ Left of equals must always be variable: 1 + 2 = x
§ Read assignment statements right-to-left!
§ Evaluate the expression on the right
§ Store the result in the variable on the left
• We can include variables in this expression
§ Example: x = y+2
§ Example: x = x+2
This is not circular!
Read right-to-left.
x 5
y 2
8/25/22 Variables & Assignments 22
23. Execute the Statement: x = x + 2
• Draw variable x on piece of paper:
5
x
8/25/22 Variables & Assignments 23
24. Execute the Statement: x = x + 2
• Draw variable x on piece of paper:
• Step 1: evaluate the expression x + 2
§ For x, use the value in variable x
§ Write the expression somewhere on your paper
5
x
8/25/22 Variables & Assignments 24
25. Execute the Statement: x = x + 2
• Draw variable x on piece of paper:
• Step 1: evaluate the expression x + 2
§ For x, use the value in variable x
§ Write the expression somewhere on your paper
• Step 2: Store the value of the expression in x
§ Cross off the old value in the box
§ Write the new value in the box for x
5
x
8/25/22 Variables & Assignments 25
26. Execute the Statement: x = x + 2
• Draw variable x on piece of paper:
• Step 1: evaluate the expression x + 2
§ For x, use the value in variable x
§ Write the expression somewhere on your paper
• Step 2: Store the value of the expression in x
§ Cross off the old value in the box
§ Write the new value in the box for x
• Check to see whether you did the same thing as your
neighbor, discuss it if you did something different.
5
x
8/25/22 Variables & Assignments 26
27. Which One is Closest to Your Answer?
A: B:
8/25/22 Variables & Assignments 27
C: D:
¯_(ツ)_/¯
5
x 7
x 5
x
5
x x
7
x
7
x
28. Which One is Closest to Your Answer?
A: B:
8/25/22 Variables & Assignments 28
C:
5
x 7
x 5
x
5
x x
7
x
7
x
✓
x = x + 2
29. Execute the Statement: x = 3.0 * x + 1.0
• You have this:
5
x 7
8/25/22 Variables & Assignments 29
x
30. Execute the Statement: x = 3.0 * x + 1.0
• You have this:
• Execute this command:
§ Step 1: Evaluate the expression 3.0 * x + 1.0
§ Step 2: Store its value in x
5
x 7
8/25/22 Variables & Assignments 30
x
31. Execute the Statement: x = 3.0 * x + 1.0
• You have this:
• Execute this command:
§ Step 1: Evaluate the expression 3.0 * x + 1.0
§ Step 2: Store its value in x
• Check to see whether you did the same thing as your
neighbor, discuss it if you did something different.
5
x 7
8/25/22 Variables & Assignments 31
x
32. Which One is Closest to Your Answer?
A: B:
8/25/22 Variables & Assignments 32
C: D:
¯_(ツ)_/¯
5
x 7
x 5
x
5
x x
22.0
x
22.0
x
22.0
x 7
x
7
x
33. Which One is Closest to Your Answer?
A: B:
8/25/22 Variables & Assignments 33
C:
5
x 7
x 5
x
5
x x
22.0
x
22.0
x
22.0
x 7
x
7
x
✓
x = 3.0 * x + 1.0
34. Execute the Statement: x = 3.0 * x + 1.0
• You now have this:
• The command:
§ Step 1: Evaluate the expression 3.0 * x + 1.0
§ Step 2: Store its value in x
• This is how you execute an assignment statement
§ Performing it is called executing the command
§ Command requires both evaluate AND store to be correct
§ Important mental model for understanding Python
5
x 7 22.0
8/25/22 Variables & Assignments 34
x x
35. Exercise: Understanding Assignment
• Add another variable, interestRate, to get this:
• Execute this assignment:
interestRate = x / interestRate
• Check to see whether you did the same thing as your
neighbor, discuss it if you did something different.
4
interestRate
5
x 7 22.0
8/25/22 Variables & Assignments 35
x x
36. Which One is Closest to Your Answer?
A: B:
8/25/22 Variables & Assignments 36
C: D:
4
interestRate
5
x 7 22.0
x x 5.5
x
5.5
x 4
interestRate
5
x 7 22.0
x x
x
4
interestRate
5
x 7 22.0
x x
5.5
x 4
interestRate
5
x 7 22.0
x x
5
x
5.5
interestRate
37. Which One is Closest to Your Answer?
A: B:
8/25/22 Variables & Assignments 37
C: D:
4
interestRate
5
x 7 22.0
x x 5.5
x
5.5
x 4
interestRate
5
x 7 22.0
x x
x
4
interestRate
5
x 7 22.0
x x
5.5
x 4
interestRate
5
x 7 22.0
x x
5
x
5.5
interestRate
E:
¯_(ツ)_/¯
38. Which One is Closest to Your Answer?
B:
8/25/22 Variables & Assignments 38
C: D:
4
interestRate
5
x 7 22.0
x x
x
4
interestRate
5
x 7 22.0
x x
5.5
x 4
interestRate
5
x 7 22.0
x x
5
x
5.5
interestRate
✓
interestRate = x/interestRate
39. Exercise: Understanding Assignment
• You now have this:
• Execute this assignment:
intrestRate = x + interestRate
• Check to see whether you did the same thing as your
neighbor, discuss it if you did something different.
4
interestRate 5.5
5
x 7 22.0
8/25/22 Variables & Assignments 39
x x x
40. Which One is Closest to Your Answer?
A: B:
8/25/22 Variables & Assignments 40
C: D:
4
interestRate
5
x 7 22.0
x x
5.5
x 4
interestRate
5
x 7 22.0
x x
x
interestRate
5
x 7 22.0
x x
interestRate
5
x 7 22.0
x x
27.5
intrestRate
5.5
4
x 5.5
27.5
intrestRate
x
27.5
x
4 5.5
x
27.5
x
41. Which One is Closest to Your Answer?
A: B:
8/25/22 Variables & Assignments 41
C: D:
4
interestRate
5
x 7 22.0
x x
5.5
x 4
interestRate
5
x 7 22.0
x x
x
interestRate
5
x 7 22.0
x x
interestRate
5
x 7 22.0
x x
27.5
intrestRate
5.5
4
x 5.5
27.5
intrestRate
x
27.5
x
4 5.5
x
27.5
x
E:
¯_(ツ)_/¯
42. Which One is Closest to Your Answer?
A: B:
8/25/22 Variables & Assignments 42
4
interestRate
5
x 7 22.0
x x
5.5
x 4
interestRate
5
x 7 22.0
x x
x
27.5
intrestRate
5.5
27.5
x
✓
intrestRate = x + interestRate
^
e
43. Which One is Closest to Your Answer?
A: B:
8/25/22 Variables & Assignments 43
4
interestRate
5
x 7 22.0
x x
5.5
x 4
interestRate
5
x 7 22.0
x x
x
27.5
intrestRate
5.5
27.5
x
✓
intrestRate = x + interestRate
^
e
Spelling mistakes in
Python are bad!!
44. Dynamic Typing
• Python is a dynamically typed language
§ Variables can hold values of any type
§ Variables can hold different types at different times
• The following is acceptable in Python:
>>> x = 1
>>> x = x / 2.0
• Alternative is a statically typed language
§ Each variable restricted to values of just one type
§ This is true in Java , C, C++, etc.
8/25/22 Variables & Assignments 44
ç x contains an int value
ç x now contains a float value
45. Dynamic Typing
• Often want to track the type in a variable
§ What is the result of evaluating x / y?
§ Depends on whether x, y are int or float values
• Use expression type(<expression>) to get type
§ type(2) evaluates to <type 'int'>
§ type(x) evaluates to type of contents of x
• Can use in a boolean expression to test type
§ type('abc') == str evaluates to True
8/25/22 Variables & Assignments 45