Professional Documents
Culture Documents
Python Fndamentals PDF
Python Fndamentals PDF
Character set- A set of valid characters recognized by python. Python uses the
traditional ASCII character set. The latest version recognizes the Unicode
character set. The ASCII character set is a subset of the Unicode character set.
The Python Character set comprises of:
❖Digits : 0–9
Words
Tokens
➢ An identifier can consist of the following characters of the Python Character set:
❖ Alphabets (A – Z, a – z)
❖ Digits ( 0 - 9)
❖ Underscore( _ ) Note: No other special character is allowed
➢ An identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero or
more letters, underscores and digits (0 to 9).
➢ Identifier must not be a keyword of Python
➢ Python is a case sensitive programming language.
Thus, name and Name are two different identifiers in Python.
Suggestion: Use names that pertains to the purpose of the variable
Some valid identifiers
a=10
X = 20-10*3
data= [“ Anil”,”Sunil”, “Vinay”]
Operators
Compound
Arithmetic Relational Logical Assignment Assignment
(Short hand)
Assignment Assignment
Compound
Arithmetic Relational Logical
= Assignment
=
Operands-Numeric(Mostly) Operands - Numeric
Operands-Numeric(Mostly) Boolean Used in an expression
Result -Numeric(Mostly) Result - Numeric
Result -Boolean Result - Boolean
Assigning a value
a=5
Assigning a variable
b=a
Assigning an
expression
c=a+b
Note:
The left of an
expression is
always a variable.
The Right may be
a constant value,
variable or an
expression
Special characteristics of + and * operators
These 2 operators behave differently with numeric and string values.
+ Operator *Operator
With numeric values: Performs Addition
Eg: 2 + 3 = 5 With numeric values: Performs Multiplication
3.5 + 2.3 = 5.8 Eg: 2 * 3 = 6
2.3 *3 = 6.9
With Strings: Performs concatenation
Eg: ‘2’ + ’3’ = ’23’ With Strings: Performs Replication
‘Hello’ +’dear ’ = “Hellodear” Eg: ‘2’ * 3 = ’222’
‘Hello’ * 3 = ‘HelloHelloHello’
Based on the number of operands required for the operation,
operators are broadly classified into:
1. Unary ( 1 operand ) Priority Highest
2. Binary ( 2 operands )
3. Ternary ( 3 operands ) Lowest
Unary Operators: Binary Operators:
➢ Arithmetic Operators : ( + - * / % ** //
➢ Assignment Operator : ( = )
Data Types
A variable is a named unit of storage. A variable helps to bind names with
objects. Associated with every variable, there are three main components :
Identity
Variable
Type
Value
Identity refers to the address (L-Value)of the variable in the memory which never
changes once created.The address can be retrieved by the id()method. Eg:
Identity
Address of the variable ‘a ‘ in the memory
Variable
Type refers to the data type of the variable. Data type refers to the type of
the variable and its associated operations on it. Python provides a variety
Type of data types which will be referred in the next slide. The type() returns the
data type of the variable in the memory. Eg:
Non-Executable
Executable
(Comments)