Chapter - 08 Python Fundamentals
Chapter - 08 Python Fundamentals
PYTHON FUNDAMENTALS
XI
Computer Science (083)
Board : CBSE
Unit 2:
Computational Thinking and Programming
Courtesy CBSE
CHAPTER - 02
PYTHON FUNDAMENTALS
INTRODUCTION
INTRODUCTION
PYTHON
CHARACTER
SET
What is Token?
1. Key
Words
5. 2.
Punctuators Identifiers
TOKENS
4.
Operators.
3. Literals
What is Keyword or reserved word?
1. Keyword/Reserved Word
What is Keyword?
and assert
break class
continue def
del elif
else except
exec finally
for from
Some Keywords of Python Language
global if
import in
is lambda
not or
pass print
raise return
try while
with yield
What is an identifier?
2. IDENTIFIERS
What is an identifier?
A Python Identifier is a name given
to a function, class, variable, module, or
other objects that you’ll be using in
your Python program.
In short, its a name appeared in the
program.
For example: a, b, c
a b and c are the identifiers and
a b & c and , are the tokens
PYTHON NAMING CONVENTIONS
OR
What is literals?
What is string?
Sequence of letters enclosed in
quotes is called string or string literal or
constant.
Python supports both form of quotes
i.e.
‘Hello’
“Hello”
Representation of String
REPRESENTATION OF STRING
Forward Indexing
REPRESENTATION OF STRING
‘\\’ Size is 1 (\ is an
escape sequence)
‘abc’ size is 3
“\ab” size is 2
“Raama\’s Laptop” size is 13
Strings with Triple Quotes
STRINGS WITH TRIPLE QUOTES
\\ Back Slash
\a ASCII Bell
\b ASCII Backspace
\f ASCII Formfeed
ESCAPE SEQUENCES
\n New Line
\r Carriage return
\t Horizontal Tab
ESCAPE SEQUENCES
\t Vertical Tab
Float type
BOOLEAN LITERALS OR CONSTANTS.
3) BOOLEAN LITERALS OR CONSTANTS.
What is function?
Function is a self contained program
segment which carries out some specific
well defined task.
For Example:
def sqr( num ):
result= num *num
print ("Square = " , result)
sqr()
PYTHON PROGRAMMING CONVENTIONS
PYTHON PROGRAMMING CONVENTIONS
78 79 80 81 82 83 84 85 86 87
2000 2016 2018 2026 2032 2044 2048 2050 2054 2068
marks refers to
location 2054
VARIABLES AND ASSIGNMENTS
Now marks = 81
78 79 80 81 82 83 84 85 86 87
2000 2016 2018 2026 2032 2044 2048 2050 2054 2068
marks refers to
location 2026
Multiple Assignments
Python is very versatile with
assignment statements.
Multiple Assignments
Multiple Assignments
Multiple Assignments
Expressions separated by commas
are evaluated from left to right.
Now,
x = 10
y,y = x+2,x+5
y,y = 12,15
First It will assign y = 12 then y = 15
So print(y) will print 15
VARIABLES AND ASSIGNMENTS
Dynamic Typing:
A variable pointing to a value of certain
type can be made to point to a value/object
of different type this is called Dynamic
Typing.
x=10
print(x)
x=“ Hello World”
print(x)
VARIABLES AND ASSIGNMENTS
Output will be
10
x
Hello World
10
10
Hello World
VARIABLES AND ASSIGNMENTS
x = ‘day’
y = x/2 Error! String can not be divided.
VARIABLES AND ASSIGNMENTS
type() function:
type() function:
Variable_to_hold_the_value=input(message)
For Example:
Where,
variable_to_Hold_the_Value is a variable
which is the label for a memory location
where the value is stored.
INPUT ( ) FUNCTION
For Example:
p = input(“Enter the value”)
x = int(input(“Enter x value”))
reads the value and converts it in to integer type
data or value.
y=float(input(“Enter y value”))
reads the value and converts it in to float type
data or value.
INPUT ( ) FUNCTION
print() Parameters:
objects - object to the printed. * indicates that
there may be more than one object
sep - objects are separated by sep. Default
value: ' ‘ end - end is printed at last
file - must be an object with write(string)
method. If omitted it, sys.stdout will be used
which prints objects on the screen.
flush - If True, the stream is forcibly
flushed. Default value: False
PRINT ( ) FUNCTION
Example 1: How print() works in Python?
print("Python is fun.")
a=5
#Two objects are passed:
print("a =", a)
b=a
# Three objects are passed:
print('a =', a, '= b‘)
Output
Python is fun.
a=5
a=5=b
PRINT ( ) FUNCTION
1. What is EOL?
2. What is an escape sequence?
3. What is the maximum line length in a python
program?
4. Write any four keywords of python language
5. What are the types of Assignment
statements? Explain
6. Explain with a diagram how a variable refers
to a memory location?
CLASS TEST ON PYTHON FUNDAMENTALS
Each carries 2 Marks Questions (10 x 2 = 20)
13.What is none?
14.What is an operator?
15.What is Unary Operator?
16.What is Binary Operator?
17.List the shift operators
18.List the Bitwise operators
19.What is an assignment statement?
20.What is Punctuators?
21.What is comment?
22.What is whitespace?
23.What is statement?
CHAPTER 2: PYTHON FUNDAMENTALS
One Mark Questions
30.What is variable?
31.What is Lvalue?
32.What is Rvalue?
33.What is an Assignment statement?
34.What is Dynamic typing?
CHAPTER 2: PYTHON FUNDAMENTALS
Two Marks Questions