The Python Interpreter Python is an interpreted language. Commands are executed through the Python interpreter. The interpreter receives a command, evaluates that command, and reports the result of the command. A programmer defines a series of commands in advance and saves those commands in a text file known as source code or a script. For Python, source code is conventionally stored in a file named with the .py suffix (e.g., demo.py).
Objects in Python Python is an object-oriented language and classes form the basis for all data types. Python’s built-in classes: the int class for integers, the float class for floating-point values, the str class for character strings.
Identifiers, Objects, and the Assignment Statement The most important of all Python commands is an assignment statement: temperature = 98.6 This command establishes temperature as an identifier (also known as a name), and then associates it with the object expressed on the right-hand side of the equal sign, in this case a floating-point object with value 98.6.
Identifiers Identifiers in Python are case-sensitive, so temperature and Temperature are distinct names. Identifiers can be composed of almost any combination of letters, numerals, and underscore characters. An identifier cannot begin with a numeral and that there are 33 specially reserved words that cannot be used as identifiers:
Types Python is a dynamically typed language, as there is no advance declaration associating an identifier with a particular data type. An identifier can be associated with any type of object, and it can later be reassigned to another object of the same (or different) type. Although an identifier has no declared type, the object to which it refers has a definite type. In our first example, the characters 98.6 are recognized as a floating-point literal, and thus the identifier temperature is associated with an instance of the float class having that value.
Objects The process of creating a new instance of a class is known as instantiation. To instantiate an object we usually invoke the constructor of a class: w = Widget() This is assuming that the constructor does not require any parameters. If the constructor does require parameters, we might use a syntax such as w = Widget(a, b, c) Many of Python’s built-in classes a literal form for designating new instances. For example, the command temperature = 98.6 results in the creation of a new instance of the float class.
Calling Methods Python supports functions a syntax such as sorted(data), in which case data is a parameter sent to the function. Python’s classes may also define one or more methods (also known as member functions), which are invoked on a specific instance of a class using the dot (“.”) operator. For example, Python’s list class has a method named sort that can be invoked with a syntax such as data.sort( ). This particular method rearranges the contents of the list so that they are sorted.
The list Class A list instance stores a sequence of objects, that is, a sequence of references (or pointers) to objects in the list. Elements of a list may be arbitrary objects (including the None object). Lists are array-based sequences and a list of length n has elements indexed from 0 to n−1 inclusive. Lists have the ability to dynamically expand and contract their capacities as needed. Python uses the characters [ ] as delimiters for a list literal. [ ] is an empty list. [‘red’, ‘green’, ‘blue’] is a list containing three string instances. The list( ) constructor produces an empty list by default. The list constructor will accept any iterable parameter. list(‘hello’) produces a list of individual characters, [‘h’, ‘e’, ‘l’, ‘l’, ‘o’].
The tuple Class The tuple class provides an immutable (unchangeable) version of a sequence, which allows instances to have an internal representation that may be more streamlined than that of a list. Parentheses delimit a tuple. The empty tuple is () To express a tuple of length one as a literal, a comma must be placed after the element, but within the parentheses. For example, (17,) is a one-element tuple.
The str Class String literals can be enclosed in single quotes, as in ‘hello’, or double quotes, as in "hello". A string can also begin and end with three single or double quotes, if it contains newlines in it.
The set Class Python’s set class represents a set, namely a collection of elements, without duplicates, and without an inherent order to those elements. Only instances of immutable types can be added to a Python set. Therefore, objects such as integers, floating- point numbers, and character strings are eligible to be elements of a set. The frozenset class is an immutable form of the set type, itself. Python uses curly braces { and } as delimiters for a set For example, as {17} or {‘red’, ‘green’, ‘blue’} The exception to this rule is that { } does not represent an empty set. Instead, the constructor set( ) returns an empty set.
Sequence Comparisons Sequences define comparison operations based on lexicographic order, performing an element by element comparison until the first difference is found. For example, [5, 6, 9] < [5, 7] because of the entries at index 1.
Fundamentals of Digital Forensics A Guide to Theory Research and Applications Joakim Kävrestad Marcus Birath Nathan Clarke - Download the ebook now and own the full detailed content
Certification and Security in Inter Organizational E Services IFIP 18th World Computer Congress August 22 27 2004 Toulouse France IFIP International Federation for Information Processing 1st Edition Enrico Nardelli pdf download
Complete Answer Guide for Test Bank for Calculus Concepts: An Informal Approach to the Mathematics of Change, 5th Edition, Donald R. LaTorre, John W. Kenelly, Iris B. Reed, Laurel R. Carpenter, Cynthia R. Harris Sherry Biggers