0% found this document useful (0 votes)
11 views23 pages

Python Fundamentals

Uploaded by

amankumar210907
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
11 views23 pages

Python Fundamentals

Uploaded by

amankumar210907
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 23

Python Fundamentals

Informatics Practices
Class - XI
By : Sheikh Gulshad Ahmad
Python Introduction
• Python 3.0 was released in 2008. Although
this version is supposed to be backward
incompatibles, later on many of its important
features have been back ported to be
compatible with version 2.7
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
• White spaces:– blank space,tab,carriage return,new
line, form feed Other characters:- Unicode
Input and Output
var1=‘Computer Science'
var2=‘Informatics Practices'
print(var1,' and ',var2,' )
Output :- Computer Science and Informatics Practices

• raw_input() Function In Python allows a user to give input to a program from a keyboard but in the
form of string. (NOTE : raw_input() function is deprecated in python 3)
– e.g.
age = int(raw_input(‘enter your age’))
percentage = float(raw_input(‘enter percentage’))
• input() Function In Python allows a user to give input to a program from a keyboard but returns the
value accordingly.
– e.g.
age = int(input(‘enter your age’))
C = age+2 #will not produce any error
Token
Smallest individual unit in a program is known as
token.
• Keywords
• Identifiers
• Literals
• Operators
• punctuators
Keywords
• Reserve word of the
compiler/interpreter
which can’t be used
as identifier.
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
Some additional naming conventions
• Class names start with an uppercase letter. All other
identifiers start with a lowercase letter.
• Starting an identifier with a single leading underscore
indicates that the identifier is private.
• Starting an identifier with two leading underscores
indicates a strong private identifier.
• If the identifier also ends with two trailing underscores,
the identifier is a language-defined special name.
Literals
• Literals in Python can be defined as number, text, or other data
that represent values to be stored in variables.
• Example of String Literals in Python
– name = ‘Johni’, fname = “johny”
• Example of Integer Literals in Python(numeric literal)
– age = 22
• Example of Float Literals in Python(numeric literal)
– height = 6.2
• Example of Special Literals in Python
– name = None
• Escape sequence
Operators
• Operators can be defined as symbols that are used to perform
operations on operands.
• Types of Operators
1. Arithmetic Operators.
2. Relational Operators.
3. Assignment Operators.
4. Logical Operators.
5. Bitwise Operators
6. Membership Operators
7. Identity Operators
Arithmetic Operators
• Arithmetic Operators are used to perform arithmetic
operations like addition, multiplication, division etc.
Relational Operators
• Relational Operators are used to compare the
values.
Assignment Operators
• Assignment Operators used to assign values to
the variables.
Operators Description Example
= Assigns values from right side operands to left side operand a=b

+= Add 2 numbers and assigns the result to left operand. a+=b

/= Divides 2 numbers and assigns the result to left operand. a/=b

*= Multiply 2 numbers and assigns the result to left operand. A*=b

-= Subtracts 2 numbers and assigns the result to left operand. A-=b

%= modulus 2 numbers and assigns the result to left operand. a%=b

//= Perform floor division on 2 numbers and assigns the result to left a//=b
operand.

**= calculate power on operators and assigns the result to left operand. a**=b
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
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.
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
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
Let us take an Example…
a = 34,b=34
if (a is b):
print('both a and b has same identity')
else:
print('a and b has different identity')
b=99
if (a is b):
print('both a and b has same identity')
else:
print('a and b has different identity')
Output :-
both a and b has same identity
a and b has different identity
• Used to implement the grammatical and structure of
a Syntax. Following are the python punctuators.
Barebone of a Python Program
Barebone of a Python Program
1. Expression : - which is evaluated and produce result. E.g. (20 + 4) / 4
2. Statement :- instruction that does something.
e.g. a = 20
print("Calling in proper sequence")
3. Comments : which is readable for programmer but ignored by python interpreter
a) Single line comment: Which begins with # sign.
b) Multi line comment (docstring): either write multiple line beginning with # sign or use triple quoted
multiple line. E.g.
‘’’this is my
first
python multiline comment ‘’’
4. Function - a code that has some name and it can be reused. e.g. keyArgFunc in above program
5. Block & indentation : group of statements is block.indentation at same level create a block.e.g. all 3
statement of keyArgFunc function
Variables
• Variable is a name given to a memory location. A variable can consider as a
container which holds value. Python is a type infer language that means you don't
need to specify the datatype of variable. Python automatically get variable
datatype depending upon the value assigned to the variable.
• Assigning Values To Variable
– name = ‘python' # String Data Type
– sum = None # a variable without value
– a = 23 # Integer
– b = 6.2 # Float
– sum = a + b
– print (sum)
• Multiple Assignment: assign a single value to many variables
– a = b = c = 1 # single value to multiple variable
– a,b = 1,2 # multiple value to multiple variable
– a,b = b,a # value of a and b is swaped
Thank You!

You might also like