Python Programming/Variables

This lesson introduces variables, expressions, and statements.

Objectives and Skills
Objectives and skills for this lesson include:
 * Language Basics
 * Language elements (constants, numbers and strings)
 * Strings types (single quotes, double quotes and triple quotes)
 * Escape Sequence, string concatenation and format method
 * Variables naming, types and objects
 * Indentation, logical and physical lines
 * Operators and Expressions
 * Operators and Expressions
 * Evaluation Order and Associativity
 * Input Output
 * User input

Readings

 * 1)  Variable (computer science)
 * 2)  Data type
 * 3)  Expression (computer science)
 * 4)  Statement (computer science)
 * 5)  Order of operations
 * 6) Python for Everyone: Variables, expressions, and statements

Multimedia

 * 1) YouTube: Python for Informatics: Chapter 2 - Expressions
 * 2) YouTube: Python Numbers
 * 3) YouTube: Python3 Input & Output
 * 4) Youtube: Python 3 Programming Tutorial: Variables
 * 5) Youtube: Setting up Pycharm and getting started

Data Types
Built-in Python data types include integer (int), floating point (float), string (str), and Boolean (bool) data types.

Type Conversion
An object’s type is accessed by the built-in function type.

Quotes
String literals are written in a variety of ways, including single quotes, double quotes, and triple quotes. Triple quoted strings may span multiple lines. The backslash (\) character is used to escape characters that otherwise have a special meaning, such as newline, backslash itself, or the quote character.

Numeric Operations
All numeric types (except complex) support the following operations, sorted by ascending priority.

Assignment Operations
An assignment statement evaluates the expression and assigns the result to the target. Augmented assignment is the combination, in a single statement, of an operation and an assignment statement.

Input Function
Python 2: If the prompt argument is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to a string (stripping a trailing newline), which is then parsed and evaluated as a Python expression.

Python 3: If the prompt argument is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that.

Tutorials

 * 1) Complete one or more of the following tutorials:
 * 2) * LearnPython
 * 3) ** Variables and Types
 * 4) ** Basic Operators
 * 5) * TutorialsPoint
 * 6) ** Basic Syntax
 * 7) ** Variable Types
 * 8) ** Basic Operators
 * 9) * Codecademy
 * 10) ** Strings and Console Output
 * 11) * SoloLearn
 * 12) ** Basic Concepts
 * 13) * Wikiversity
 * 14) ** Python/Numbers
 * 15) * Wikibooks
 * 16) ** A Beginner's Python Tutorial/Variables, Scripts

Practice

 * 1) Experiment with different numeric operations to ensure you understand how they work.  Then review either MathsIsFun: Order of Operations or  Teachoo: What is BODMAS?.  Create a Python program that demonstrates the order of operations.
 * 2) Create a Python program to prompt the user for hours and rate per hour to compute gross pay (hours * rate).
 * 3) Review MathsIsFun: Conversion of Temperature.  Create a Python program that asks the user for a Fahrenheit temperature and then calculate and display the corresponding Celsius temperature or ask the user for a Celsius temperature and then calculate and display the corresponding Fahrenheit temperature.
 * 4) Create a Python program that asks the user how old they are in years, and then calculate and display their approximate age in months, days, hours, and seconds.
 * 5) Review MathsIsFun: Area of Plane Shapes.  Create a Python program that asks the user for the dimensions of different shapes and then calculate and display the area of the shapes.

Games

 * 1) Play CodeCombat.

Lesson Summary

 * Built-in Python data types include integer, floating point , string , and Boolean.
 * An object’s type is accessed by the built-in function.
 * String literals are written in a variety of ways, including single quotes, double quotes, and triple quotes. Triple quoted strings may span multiple lines.
 * The backslash character is used to escape characters that otherwise have a special meaning, such as newline, backslash itself, or the quote character.
 * Numeric operators include,  ,  ,  ,  ,  , and.
 * Assignment operators include,  ,  ,  ,  ,  , and.
 * The Python 2  function reads a line from input, converts it to a string (stripping a trailing newline), which is then parsed and evaluated as a Python expression.
 * The Python 3  function reads a line from input, converts it to a string (stripping a trailing newline), and returns that.

Key Terms

 * assignment
 * A statement that assigns a value to a variable.


 * concatenate
 * To join two operands end to end.


 * comment
 * Information in a program that is meant for other programmers (or anyone reading the source code) and has no effect on the execution of the program.


 * escape character
 * A character which invokes an alternative interpretation on subsequent characters in a character sequence.


 * evaluate
 * To simplify an expression by performing the operations in order to yield a single value.


 * expression
 * A combination of variables, operators, and values that represents a single result value.


 * floating point
 * A type that represents numbers with fractional parts.


 * floor division
 * The operation that divides two numbers and chops off the fractional part.


 * integer
 * A type that represents whole numbers.


 * keyword
 * A reserved word that is used by the compiler to parse a program; you cannot use keywords like if, def, and while as variable names.


 * mnemonic
 * A memory aid. We often give variables mnemonic names to help us remember what is stored in the variable.


 * modulus operator
 * An operator, denoted with a percent sign (%), that works on integers and yields the remainder when one number is divided by another.


 * operand
 * One of the values on which an operator operates.


 * operator
 * A special symbol that represents a simple computation like addition, multiplication, or string concatenation.


 * rules of precedence
 * The set of rules governing the order in which expressions involving multiple operators and operands are evaluated.


 * statement
 * A section of code that represents a command or action. So far, the statements we have seen are assignments and print statements.


 * string
 * A type that represents sequences of characters.


 * type
 * A category of values. The types we have seen so far are integers (type int), floating-point numbers (type float), and strings (type str).


 * value
 * One of the basic units of data, like a number or string, that a program manipulates.


 * variable
 * A name that refers to a value.

Assessments

 * Flashcards: Quizlet: Python Variables
 * Flashcards: Quizlet: Python Variable Types
 * Flashcards: Quizlet: Python Variables, Expressions, and Statements
 * Quiz: Quizlet: Python Variables
 * Quiz: Quizlet: Python Variable Types
 * Quiz: Quizlet: Python Variable, Expressions, and Statements