[go: up one dir, main page]

0% found this document useful (0 votes)
38 views35 pages

Chapter 1 Cls 12

reviosn tour 1 python
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views35 pages

Chapter 1 Cls 12

reviosn tour 1 python
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

Chapter 1:: Revision tour 1 (Topics covered in grade

11 )
Python (a computer language)
• We know that Python is a powerful and high level language and it is an interpreted
language.
• Python gives us two modes of working-
– Interactive mode
– Script mode

ScriptMode
Interactive
Mode

• It is possible to develop various Apps with Python like–


– GUI Apps
– Web Apps
– Games
– DBMS Apps
– Scripting etc.

Python (Limitations)
There are few limitations in Python which can be neglected because of its
vast usage.
• It is not a Fast Language.
• Libraries are very less.
• It is week in Type binding.
• It is not easy to convert some other
language.

Tokens
• Token- is the smallest unit of any programming language.

It is also known as Lexical Unit. Types of token are-


i. Keywords
ii. Identifiers (Names)
iii. Literals
iv. Operators
v. Punctuator

Keywords::
• Keywords are those words which provide a special meaning to the interpreter.
• These are also known as reserve words. These can’t be used as identifiers variable name or
any other purpose.

Available keywords in Python are


Identifiers
• These are building blocks of a program and are used to give names to
different parts/blocks of a program like - variable, objects, classes, functions.
• An identifier may be a combination of letters and numbers.
• An identifier must begin with an alphabet or an underscore ( _ ).
Subsequent letters may be numbers (0-9).
• Python is case sensitive. Uppercase characters are distinct from lowercase characters
(P and p are different for interpreter).
• Length of an Identifier is unlimited.
• Keywords can not be used as an identifier.
• Space and special symbols are not permitted in an identifier name except an underscore( _ ) sign.
• Some valid identifiers are –
• Myfile, Date9_7_17, Z2T0Z9, _DS, _CHK FILE13.
• Some invald identifiers are –
• DATA-REC, 29COLOR, break, My.File
Literals / Values

• Literals are often called Constant Values.

• Python permits following types of literals -

– String literals - “Pankaj”


– Numeric literals – 10, 13.5, 3+5j

– Boolean literals – True or False

– Special Literal None

– Literal collections

String Literals:
String Literal is a sequence of characters that can be a combination of letters, numbers and special
symbols, enclosed in quotation marks, single, double or triple(“ “ or ‘ ‘ or “’ ‘”).
In python, string is of 2 types
Single line string
Text = “Hello World” or Text = ‘Hello World”
Multi line string
Text = ‘hello\ or Text = ‘’’hello
world’ word”
Numeric Literals
• Numeric values can be of three types -

– int (signed integers)


• Decimal Integer Literals – 10, 17, 210 etc.
• Octal Integer Literals - 0o17, 0o217 etc.
Hexadecimal Integer Literals – 0x14, 0x2A4, 0xABD etc
– float ( floating point real value)
• Fractional Form – 2.0, 17.5 -13.5, -.00015 etc.
Exponent Form - -1.7E+8, .25E-4 etc
– complex (complex numbers)
• 3+5i etc.
• Boolean Literals :: It can contain either of only two values – True or False
▪ A= True
▪ B=False

• Special Literals:: None, which means nothing (no value).


▪ X = None
Operators
• An Operator is a symbol that trigger some action when
applied to identifier (s)/ operand (s)
• Therefore, an operator requires operand (s) to compute upon. example :
c=a+b
Here, a, b, c are operands and operators are = and + which are performing differently.
Punctuators
• In Python, punctuators are used to construct the program and to make balance between instructions
and statements. Punctuators have their own syntactic and semantic significance.
• Python has following Punctuators -
‘, ”, #, \, (, ), [, ], {, }, @. ,, :, .. `, =
CORE DATA TYPES

CORE
DATA TYPE

Numbers None Sequences Mappings

Floating
Integer Complex String Tuple List Dictionary
Point

Boolean

Variables and Values :


An important fact to know is-
In Python, values are actually objects.
And their variable names are actually their reference names.
Suppose we assign 10 to a variable A.
A = 10

Here, value 10 is an object and A is its reference name


Mutable and Immutable Types

Following data types comes under mutable and immutable types-

• Mutable (Changeable)
lists, dictionaries and sets.

• Immutable (Non-Changeable)

integers, floats, Booleans, strings and tuples


Operators

• The symbols that shows a special behavior or action when applied to operands are called operators.
For ex- + , - , > , < etc.
• Python supports following operators-
I. Arithmetic Operator
II. Relation Operator
III. Identity Operators
IV. Logical Operators
V. Bitwise Operators
VI. Membership Operators

Operator Associativity

• In Python, if an expression or statement consists of multiple or more than one operator then operator
associativity will be followed from left-to- right.

• In above given expression, first 7*8 will be calculated as 56, then 56 will be divided by 5 and will
result into 11.2, then 11.2 again divided by 2 and will result into 5.0.
*Only in case of **, associativity will be followed from right-to-left.

Above given example will be calculated as 3**(3**2)


Type Casting
• As we know, in Python, an expression may be consists of mixed datatypes. In such cases, python
changes data types of operands internally. This process of internal data type conversion is called
implicit type conversion.
• One other option is explicit type conversion which is like-
<datatype> (identifier)
If a=5 and b=10.5 then we can convert a to float. Like d=float(a)

Other example:: a=“4”


b=int(a)

Statement Flow Control


• .
In a program, statements executes in sequential manner or in selective manner or in iterative manner
Sequential Selective Iterative
Python -----if Statements

• In Python, if statement is used to select statement for processing. If execution of a statement is to be


done on the basis of a condition, if statement is to be used. Its syntax is-

if <condition>:
statement(s)
l
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Python---if-else Statements
If out of two statements, it is required to select one statement for processing on the basis of a condition,
if-else statement is to be used. Its syntax is-

if <condition>:
statement(s) when condition is true
else:
statement(s) when condition is false
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Nested If -else:

Neha Tyagi, KV 5 Jaipur II Shift


Loop/Repetitive Task/Iteration
These control structures are used for repeated execution of statement(s) on the basis of a condition. Loop
has 3 main components-
1. Start (initialization of loop)
2. Step (moving forward in loop )
3. Stop (ending of loop)

Python has following loops-

• for loop
• while loop

.
Range () Function

• In Python, an important function is range( ). its syntax is-


range ( <lower limit>,<upper limit>) If we write - range (0,5 )
Then a list will be created with the values [0,1,2,3,4] i.e. from
lower limit to the value one less than ending limit.
range (0,10,2) will have the list [0,2,4,6,8]. range (5,0,-1) will have the list [5,4,3,2,1]

Jump Statements Break Statement

.
for <var> in <sequence>: statement1
while <test-condition>: statement1 if <condition>: break
if <condition>: break statement2
statement2 statement3
statement3 Statement4
Statement4 statement5
statement5
Jump Statements Break Statement

Output Output

.
in and not in operator

• in operator-
3 in [1,2,3,4] will return True.

5 in [1,2,3,4] will return False .

• not in operator-
5 not in [1,2,3,4] will return True.

.
Jump Statements Continue Statement

Output of both the program---

.
Nested Loop

OUTPUT

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Previous Year Questions


.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

You might also like