Wade: Chapter 4: Learning Python Language Fundamentals

Mack Wade

Chapter 4: Learning Python Language Fundamentals

Terms

Boolean: denoting a system of algebraic notation used to represent logical propositions, especially in computing and electronics.

Boolean Expression: In computer science, a Boolean expression is an expression used in programming languages that produces a Boolean value when evaluated. A Boolean value is either true or false.

Boolean Logic: In mathematics and mathematical logic, Boolean algebra is the branch of algebra in which the values of the variables are the truth values true and false, usually denoted 1 and 0, respectively.

Boolean OPerator: Boolean Operators are simple words (AND, OR, NOT or AND NOT) used as conjunctions to combine or exclude keywords in a search, resulting in more focused and productive results. This should save time and effort by eliminating inappropriate hits that must be scanned before discarding.

Built in Operator: These operators are used to perform arithmetic computations on their operands. This operator returns the result of adding the two operands (operand1 and operand2).

Camel Case: Camel case is the practice of writing phrases without spaces or punctuation, indicating the separation of words with a single capitalized letter, and the first word starting with either case. Common examples include “iPhone” and “eBay”

Casting: Casting is when you convert a variable value from one type to another.

Comparison Operator: Comparison operators — operators that compare values and return true or false . The operators include: > , < , >= , <= , === , and !== 

Condition: The boolean expression in a conditional statement that determines which branch is executed

Docstring: a string literal specified in source code that is used, like a comment, to document a specific segment of code

Dot Notation: You can access properties on an object by specifying the name of the object, followed by a dot (period) followed by the property name.

Escape character: a character that invokes an alternative interpretation on the following characters in a character sequence.

Float: a data type composed of a number that is not an integer, because it includes a fraction represented in decimal format.

Floor Division: a normal division operation except that it returns the largest possible integer.

F-String: provide a way to embed expressions inside string literals, using a minimal syntax

Immutable: unchanging over time or unable to be changed.

Indexing: a way to refer the individual items within an iterable by its position

Modulus: The Python modulo operator calculates the remainder of dividing two values. This operator is represented by the percentage sign (%). The syntax for the modulo operator is: number1 % number2. The first number is divided by the second then the remainder is returned

Parameter: he variable listed inside the parentheses in the function definition.

Sentry Variable: a variable used in the condition and it is compared to some other value or values

Snake Case: refers to the style of writing in which each space is replaced by an underscore character, and the first letter of each word written in lowercase. It is a commonly used naming convention in computing, for example for variable and subroutine names, and for filenames.

String: an immutable sequence data type. It is the sequence of Unicode characters wrapped inside single, double, or triple quotes

True Division: When dividing something by 1, the answer will always be the original number

Unicode:  Unicode, formally the Unicode Standard, is an information technology standard for the consistent encoding, representation, and handling of text expressed in most of the world’s writing systems.

Whitespace: characters which are used for spacing, and have an “empty” representation. In the context of python, it means tabs and spaces

Zero-Based Language: Zero-based numbering is a way of numbering in which the initial element of a sequence is assigned the index 0, rather than the index 1 as is typical in everyday non-mathematical or non-programming circumstances

Review Questions

  1. What are the main data types in Python?
    1. The most common ones are float (floating point), int (integer), str (string), bool (Boolean), list, and dict (dictionary). float – used for real numbers. int – used for integers. 
  2. What are unicode strings?
    1. A Unicode string is a sequence of zero or more code points.
  3. What is dot notation?
    1. In general, dot notation tells Python to look inside the space that is before the dot for code to execute. You can use dot notation to access the specific version of a certain function that is defined in a different class or a different module.
  4. Name three methods of string objects in Python.
    1. The static method, the class method, and the instance method.
  5. What are some of the key similarities and differences between lists and tuples in python.
    1. list and tuple are a class of data structure that can store one or more objects or values. A list is used to store multiple items in one variable and can be created using square brackets. Similarly, tuples also can store multiple items in a single variable and can be declared using parentheses.
  6. Describe the use of Boolean expressions to evaluate a condition.
    1. A Boolean expression is a logical statement that is either TRUE or FALSE . Boolean expressions can compare data of any type as long as both parts of the expression have the same basic data type. You can test data to see if it is equal to, greater than, or less than other data.
  7. Describe the steps to create a dictionary and add new items to the dictionary.
    1. A Dictionary can be created by placing a sequence of elements within curly {} braces, separated by ‘comma’. Dictionary holds a pair of values, one being the Key and the other corresponding pair element being its Key:value.
  8. Describe how branching is implemented in Python code.
    1. Branching statements in Python are used to change the normal flow of execution based on some condition. The return branching statement is used to explicitly return from a method. A break branching statement is used to break the loop and transfer control to the line immediately outside of loop. 
  9. What is a compound statement in Python? 
    1. Compound statements are made up of two or more program statements that are executed together. This usually occurs while handling conditions wherein a series of statements are executed when a TRUE or FALSE is evaluated. Compound statements can also be executed within a loop.
  10. Describe the two main looping structures in Python.
    1. “For” and “While” For loops can iterate over a sequence of numbers using the “range” and “xrange” functions. The difference between range and xrange is that the range function returns a new list with numbers of that specified range, whereas xrange returns an iterator, which is more efficient.For loops can iterate over a sequence of numbers using the “range” and “xrange” functions. The difference between range and xrange is that the range function returns a new list with numbers of that specified range, whereas xrange returns an iterator, which is more efficient.
  11. Why should you add comments to your scripts?
    1. Using comments in any script or code is very important to make the script more readable. Comments work as a documentation for the script. The reader can easily understand each step of the script if it is properly commented by the author.