Python Fundamentals: Dinesh Arya PGT Cs KV NHPC Dharchula
Python Fundamentals: Dinesh Arya PGT Cs KV NHPC Dharchula
Fundamentals
Dinesh Arya
PGT CS
KV NHPC Dharchula
Introduction
Python 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
Letters :– A-Z,a-z
Digits :– 0-9
Special
symbols :–
Special symbol
available over
keyboard
as finally or
continue if return
del in while
elif is with
except
Identifiers
A Python identifier is a name used to identify a variable,
function, class, module or other object.
*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).
* Python does not allow special characters
* Identifier must not be a keyword of Python.
* Python is a case sensitive programming language.
Thus, Rollnumber and rollnumber are two different identifiers
in Python.
Some valid identifiers : Mybook, file123, z2td, date_2, _no
Some invalid identifier : 2rno,break,my.book,data-cs
Identifiers-continue
Some additional naming conventions
1. Class names start with an uppercase letter. All other
identifiers start with a lowercase letter.
Types of Operators
1. Arithmetic Operators.
2. Relational Operators.
3. Assignment Operators.
4. Logical Operators.
5. Bitwise Operators
6. Membership Operators
7. Identity Operators
Operators continue
1. Arithmetic Operators
Arithmetic Operators are used to perform arithmetic operations like
addition, multiplication, division etc.
Operators Description Example
= Assigns values from right side operands to left side operand a=b
//= Perform floor division on 2 numbers and assigns the result to left operand. a//=b
**= calculate power on operators and assigns the result to left operand. a**=b
Operators continue
4. Logical Operators
Logical Operators are used to perform logical operations on the
given two variables or values.
a=30
b=20
if(a==30 and b==20):
print('hello')
Output :-
hello
Operators continue
6. Membership Operators
The membership operators in Python are used to validate whether a
value is found within a sequence such as such as strings, lists, or
tuples.
Operators Description Example
not in return true if value does not exists in the sequence, else false. a not in list
E.g.
a = 22
list = [22,99,27,31]
In_Ans = a in list
NotIn_Ans = a not in list
print(In_Ans)
print(NotIn_Ans)
Output :-
True
False
Visit : python.mykvs.in for regular updates
Operators continue
7. Identity Operators
Identity operators in Python compare the memory locations of two objects.
Operators Description Example
is returns true if two variables point the same object, else false a is b
is not returns true if two variables point the different object, else false a is not b
e.g.
a = 34
b=34
if (a
is b):
pri
nt('
bot
ha
an
db
has
sa
me
Visit : python.mykvs.in for regular updates
ide
ntit
Punctuators
Used to implement the grammatical and structure of a Syntax.Following
are the python punctuators.
fun()
print(x) #error
will be shown
2. Global
Variable
x=8
def fun():
print(x)
#
Calling
variabl
e ‘x’
inside
fun()
Local & Global Variables
Output :-
1
2
2
print('hell
o India')
Output :-
h
e
l
l
o
I
Input From Keyboard
variable = input(< Prompt to display>)
e.g. name= input(‘What is your name:’)
The input () function always returns a value of string type .
If you enter integer value it will be treated as string .