Python 1

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

SUBJECT – COMPUTER SCIENCE (python)

SUBJECT CODE – 083


CLASS – XII

By: Kumud Chauhan

CHAPTER – 1 ( REVIEW OF PYTHON )

Python (A computer language)


Python is a powerful scripting , high level and object oriented programming language
and it is an interpreted language.
•It is possible to develop various Apps with Python like– GUI Apps ,Web
Apps ,Games ,DBMS Apps,
Scripting etc.

Limitations - It is not a Fast Language.


Libraries are very less.
It is week in Type binding.
It is not easy to convert in some other language.

Python gives us two modes of working-


1. Interactive ( command prompt) mode.
2. Script mode

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.Punctuators

(i) Keywords
Keywords are those words which provides a special meaning to interpreter. These
are reserved for specific functioning. These can not be used as identifiers, variable
name or any other purpose. Available keywords are as input, print, and, none,
while, for, def, del, def etc.

(ii) 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.

(iii) Literals / Values

Literals are often called Constant Values.


•Python permits following types of literals -
1. String literals - “Pankaj”
2. Numeric literals – 10, 13.5, 3+5j ( int, float, complex)
3. Boolean literals – True or False
4. Special Literal - None

(iv) 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

(v) Punctuators
punctuators are used to construct the program and to make balance between instructions and
statements. •Python has following Punctuators -

‘, ”, #, \, (, ), [, ], {, }, @. ,, :, .. `, =

DATA TYPES
Variables can hold values of different types called data types. like- character, integer, real, string.
• Anything enclosed in “ “ is considered as string in Python.
•Any whole value is an integer value.
• Any value with fraction part is a real value.
•True or False value specifies Boolean value.

CORE DATA TYPES -


1. Numbers (int like10, 5) (float like 3.5, 302.24) (complex like 3+5j)
2. String (like “pankaj”, ‘pankaj’, ‘a’, “a” )
3. List like [3,4,5,”pankaj”] its elements are Mutable.
4. Tuple like(3,4,5,”pankaj”) its elements are immutable.
5. Dictionary like {‘a’:1, ‘e’:2, ‘I’:3, ‘o’:4, ‘u’:5} where a,e,i,o,u are keys and 1,2,3,4,5 are their
values.

Operators :-
The symbols that shows a special behavior or action when applied to operands are called
operators. For ex- + , - , > , < etc.
• Python supports following operators-

Arithmetic Operator : +, -, *, /, //, %, ** etc


Relation Operator : <, >, = = , !=,
Identity Operators : is, is not
Logical Operators : Not, or, and
Bitwise Operators : are used to perform bitwise calculations on integers. The integers are
first converted into binary and then operations are performed on bit by bit, hence the name
bitwise
operators.
Operator Description Syntax
& Bitwise AND x&y
| Bitwise OR x|y
~ Bitwise NOT ~x
^ Bitwise XOR x^y
>> Bitwise right shift x>>
Membership Operators : in, not in
Input function:
input () function is used to take input which takes input in the form of string
Types of statements in Python
»Empty Statements
•pass
»Simple Statements (Single Statement)
•name=input (“Enter your Name “)
•print(name) etc.
»Compound Statements
•<Compound Statement Header>:

<Indented Body containing multiple simple statements/compound statements>


•Here, Header line starts with the keyword and ends at colon (:).
The body consists of more than one simple Python statements or compound statements.

Statement Flow Control


Statements executes in sequential manner or in selective manner or in iterative manner .
Sequential

Selective Iterative

You might also like