Python Programming Fundamentals
PYTHON CHARACTER SET
Set of valid characters recognised by Python, represents any letter, digit or any other symbols present on
the keyboard (special symbols, whitespace and other 256 ASCII characters)
TOKEN
Smallest element of a Python that is meaningful to the interpreter.
Keyword: Reserved words of Python and have special fixed meaning and can’t be used as identifiers.
Identifiers: Variable, constant, function or module. Must not start with digit, contain special character
expect underscore, space and reserved words can’t be used. Upper and lower case are treated
different.
Literals: Fixed numeric or non numeric value defined as number, text or other data that represents
values to be stored in variables.
String, Numeric, Float, Boolean, Collection and None
Operators: Symbol or word that performs some kind of operations
Punctuators: Symbols which can be used as separators of values or to enclose some values.
NOTE: Function id() returns the identity of an object.
VARAIBLE AND DATA TYPES
Variable is like a container that stores values that can be changed by user. It may vary during the
execution of a program i.e. variable keeps changing during program execution. Variable is a named unit of
storage i.e. symbolic name that refers to an object or value stored in the computer's memory as a
placeholder.
Numbers: Stores numerical values. 3 Types of built in numeric data types:
int(integer): Represents whole number without any fractional part.
float: Denote real numbers with fractional parts, written with decimal that separates the integer from
fractional numbers.
complex: Made up of pairs of real and imaginary numbers (x+yj)where x is float and real part, y is a
float and J or j indicates square root of an imaginary number -1.
Boolean: Two possible values - True or False
Sequences: Group of items with well defined ordering indexed by integer. 3 Types are:
String: Sequence of character which are combination of letters, numbers and special symbols,
enclosed within quotation marks.
List: Sequence of items separated by commas and items are enclosed in square brackets [ ]
Tuple: Sequence of items separated by commas and items are enclosed in parentheses ( )
Mappings: Immutable values to arbitrary objects. It is ordered and mutable
Dictionary: Holds data item in key-value pairs. Enclosed in curly brackets { } and is separated using a
colon (:). In order to access any value, we have to specify in square brackets [ ].
None: Special data type with a single value. Signify absence of value/condition evaluating to false in a
situation. Represented by None
USAGE OF PYTHON DATA TYPES
type() to determine the type of variable assignment(=) provide a means to name values
VARAIBLE NAMES
Must start with alphabet/underscore - can’t contain spaces or special character - Case sensitive
TYPE CONVERSION int(x) - float(x) - str(x) - chr(x)
OPERATORS %(Remainder) **(Exponentiation) //(Floor Division, Quotient)
RELATIONAL !=, <> (not equal to) == (equal to)
LOGICAL and (both) or(either) not(reverse the state)
MEMBERSHIP in(exists in string) not in (doesn’t exist)
IDENTITY is (point at same) is not (not point at same)
USER INPUT input( ) eval ( )
COMMENTS (using #) DEBUGGING (finding errors)
Syntax (Syntax of sequence of characters) - Runtime (Abnormal program termination) - Logical
(Produces undesired output)