Python Programming Fundamentals
1. Tokens
It is the smallest individual element or unit of the
python program that is meaning to the interpreter.
Each component of the programming statement is
referred to as tokens
Tokens
Keywords Identifiers Literals Operators Puncuators
Keywords
they are reserved words that have special meaning
and severe specific purpose. They cannot be used as
the names of the variables, functions and class of any
other identifier
Identifiers
It is a user defined name given to a variable, function,
class etc. The identifier is a combination of characters,
digits and underscore they are CASE SENSETIVE
(Student and STUDENT are two different variables
interpreted by python)
RULES OF NAMING PYTHON IDENTIFIERS
a. It cannot be reserved python keyword
b. It should not contain white space
c. It is combined of A-Z, a-z ,0-9 or underscore
d. It should start with an alphabet character or
underscore
e. It should not contain any special character
except underscore
Literals
It is a fixed numeric value used directly in a
program is called a literal. They are also called as
constant.
Literals
String Numeric Floating Boolean Collection None
Literals Literlas Literals Literals Literals Literals
Represented Numbers of Predefined A special
Text Enclosed decimal
numbers of data structure literal that
in single, points i.e. real Represented
different used to create indicates the
double or numbers with Boolean value
types of collection like absence of a
triple quotes +/- sign
integers lists, tuples value or
and unidentified
dictionaries value
Operators
They are used to perform specific mathematical or
logical operation on values. The values that the
operator work on called operands.
TYPES OF OPERATORS
a. Arithmetic Operators: They are the operators are
symbols used to perform mathematical
operations on numerical values. Arithmetic
operations like (+, -, *, /, %, **)
b. Relational Operators: They are also called as
comparison operators. They are used to
compare the value of the operands. It gives
answer in Boolean
For example (>, <, ==, =,>=, <=)
c. Assignment Operator: It assigns or changes the
value of the variable on its left
for example:
[a (+, -, *, /) =2 so it means = a (+, -, *, /)2]
d. Logical Operators: There three type of logical
operators (and, or, not) supported by python.
These operators are to be written in lower case
only. They evaluate only in true and false case
NOT CASE
T, ->F
F, ->T
OR CASE
T, T->T
T, F->T
F, T->T
F, F->F
AND CASE
T, T-> T
T, F-> F
F, T-> T
F, F-> F
e. Identify Operators: they are used to determine
whether the value of a variable is a certain type
or not. Identity operator are used to determine
whether two variables are referring to same
subject or not
IS CASE (If one identifier is referred to another
identifier with same value it gives true answer else
false)
IS NOT CASE (If one identifier is referred to another
identifier with different it gives false answer else
true)
f. Membership Operator: they are used to check if
a value is a member of a sequence or not
IN CASE (if one value is a part of the
sequence then true else false)
NOT IN CASE (If one value Is not a part of
the sequence then true else false)
Variables
it is a name in which we store any value.
Comments
They are inexecutable code by interpreter. They are used to
add a remark or note in the source code. They added with
the purpose of making the code easier for humans to
understand. MADE BY # SIGN
a. Single line Comment: it is a one-line comment and
created by #
b. Multiline Comment: More than one-line comment and
created by [“”” ….”””]
Data Types in Python
Number
These are the types of datatype which store
numerical values only. It is further classified into three
different types
a. Integer: Any +ve , -ve or 0 value stored
b. Float: Any decimal value stored
c. Complex: Imaginary number stored
Boolean
It is a subtype of integer. It is a unique data type
consisting of two constant True and False are
Non-zero, Non-null and Non-empty
Sequence
It is an ordered collection of items where each item is
indexed by an integer. There are three types of
sequence
a. Strings: They are group of characters which could
be inserted into single comma or double comma
b. List: it is a sequence of items which are enclosed in
square brackets
c. Tuple: it is a sequence of items which are enclosed in
parenthesis, unlike list where value enclosed in square
brackets, Once created we cannot change the tuple
Set
It is an unorder collection of items separated by
commas and items are enclosed in curly brackets
unlike list it cannot have duplicated entries once
created elements of a set cannot be changed
None
It is a special data type when we don’t have to assign
any value
Mapping
It is an unordered data type in python, currently only
dictionary is the type of mapping
a. Dictionary: It holds data items in key value pairs.
Items in a dictionary are enclosed in curly brackets
It permits faster access to data
Expression
It is a defined as a combination of constant, variables and
operators.
Input and Output
To get some data or information from the end user is INPUT,
in python we input data using input function IT ONLY ACCEPT
STRING INPUT
To show result on the screen is Output, in python we use
print to show output
Type Conversion
Conversion from datatype to another datatype is called type
conversion. There are two types of type conversion
a. Explicit Conversation: also called as type casting
happens when data type conversation takes place
because the programmer forced it in the program
b. Implicit Conversation: It happens when data type
conversation is done automatically by python and is not
instructed by the programmer.
Debugging
Removing or fixing bugs from a program is called debugging
Errors occurring in a program can be
a. Syntax error: python has its own rules so the interpreter
interprets the statement only if its syntactically correct
(according to rules of python)
b. Logical errors: the errors or undesired output by the
wrong logics used by the programmer
c. Runtime error: when the statement is correct
syntactically but cannot be executed, they do not
appear until the program has been executed or run