Python-review1

Python-review1 - Python Review 1 Jay Summet CS 1 with...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
Jay Summet CS 1 with Robots IPRE Python Review 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Outline Introduction to Python Variables: Names for data Functions Program Flow (Branching) Input from the user Iteration (Looping)
Background image of page 2
3 Introduction to Python Python is an interpreted programming language A program is a set of instructions telling the computer what to do. It has a strict syntax, and will only recognize very specific statements. If the interpreter does not recognize what you have typed, it will complain until you fix it.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Operators Python has many operators. Some examples are: +, -, *, /, %, >, <, == print Operators perform an action on one or more operands. Some operators accept operands before and after themselves: operand1 + operand2 , or 3 + 5 Others are followed by one or more operands until the end of the line, such as: print “Hi!”, 32, 48 When operators are evaluated, they perform action on their operands, and produce a new value.
Background image of page 4
5 Example Expression Evaluations An expression is any set of values and operators that will produce a new value when evaluated. Here are some examples, along with the new value they produce when evaluated: 5 + 10 produces15 “Hi” + “ “ + “Jay!” produces“Hi Jay!” 10 / (2+3) produces 2 10 > 5 producesTrue 10 < 5 producesFalse 10 / 3.5 produces2.8571428571 10 / 3 produces3 10 % 3 produces1
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 List of Operators: +, -, *, /, <, >, <=, >=, ==, % Some operators should be familiar from the world of mathematics such as Addition (+), Subtraction (-), Multiplication (*), and Division (/). Python also has comparison operators, such as Less- Than (<), Greater-Than (>), Less-Than-or-Equal(<=), Greater-Than-or-Equal (>=), and Equality-Test (==). These operators produce a True or False value. A less common operator is the Modulo operator (%), which gives the remainder of an integer division. 10 divided by 3 is 9 with a remainder of 1: 10 / 3 produces 3, while 10 % 3 produces 1
Background image of page 6
7 DANGER! Operator Overloading! NOTE! Some operators will work in a different way depending upon what their operands are. For example, when you add two numbers you get the expected result: 3 + 3 produces 6. But if you “add” two or more strings, the + operator produces a concatenated version of the strings: “Hi” + “Jay” produces “HiJay” Multiplying strings by a number repeats the string! “Hi Jay” * 3 produces “Hi JayHi JayHiJay” The modulo operator also works differently with strings: “test %f” % 34 produces “test 34.000”
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 Data Types In Python, all data has an associated data “Type”. You can find the “Type” of any piece of data by using the type() function: type( “Hi!”) produces <type 'str'> type( True ) produces <type 'bool'> type( 5) produces <type 'int'> type(5.0) produces <type 'float'> Note that python supports two different types of numbers, Integers (int) and Floating point numbers (float). Floating Point numbers have a fractional part (digits after the decimal place), while Integers do not!
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 42

Python-review1 - Python Review 1 Jay Summet CS 1 with...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online