0% found this document useful (0 votes)
63 views33 pages

1.1-Basics of Python Pog

The document discusses key concepts in Python programming such as: - The structure of a Python program includes modules, functions, libraries, statements, expressions and objects. - Python uses indentation to indicate blocks of code. The indentation level must be consistent or the code will produce a syntax error. - The basic building blocks or tokens in Python are keywords, identifiers, literals, operators, and punctuators. - Variables are containers that hold values and Python uses dynamic typing where the datatype is inferred based on the value assigned.

Uploaded by

monish pm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views33 pages

1.1-Basics of Python Pog

The document discusses key concepts in Python programming such as: - The structure of a Python program includes modules, functions, libraries, statements, expressions and objects. - Python uses indentation to indicate blocks of code. The indentation level must be consistent or the code will produce a syntax error. - The basic building blocks or tokens in Python are keywords, identifiers, literals, operators, and punctuators. - Variables are containers that hold values and Python uses dynamic typing where the datatype is inferred based on the value assigned.

Uploaded by

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

NAVODAYA VIDYALAYA SAMITI

HYDERABAD REGION

SUBJECT : COMPUTER SCIENCE


CLASS : XII
TOPIC : PYTHON REVISION TOUR
SANTOSH KUMAR PGT COMPUTER SCIENCE
JNV DAKSHINA KANNADA, KARNATAKA
Structure of a python program
Program
|->Module -> main program
| -> functions
| ->libraries
|->Statements -> simple statement
| ->compound statement
|->expressions -> Operators
| -> expressions
|----à objects ->data model
Python basics
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
 the characters:- Unicode
Input and Output
var1=‘Computer Science‘, var2=‘Informatics Practices‘
print(var1,' and ',var2,' )

Output :-
Computer Science and Informatics Practices

input() Function In Python allows a user to give input


to a program from a keyboard but in the form of string.

age = int(input(‘enter your age’))


percentage = float(input(‘enter percentage’))
Input and Output
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

NOTE : input() function always enter string


value in python 3. So on need
int(),float()function can be used for data
conversion.
Simple Python program
Interactive Mode
Interactive mode, also known as the REPL provides
us with a quick way of running blocks or a single
line of Python code. The code executes via the
Python shell, which comes with Python installation.
Simple Python program
Script Mode
If you need to write a long piece of Python code or your
Python script spans multiple files, interactive mode is not
recommended. Script mode is the way to go in such cases.
In script mode, You write your code in a text file then save
it with a py. extension which stands for "Python". Note that
you can use any text editor for this, including Sublime,
Atom, notepad++, etc.
If you are in the standard Python shell, you can click "File"
then choose "New" or simply hit "Ctrl + N" on your keyboard
to open a blank script in which you can write your code.
You can then press "Ctrl + S" to save it.
Simple Python program
After writing your code, you can run it by clicking "Run"
then "Run Module" or simply press F5.
Indentation
Indentation refers to the spaces applied at the beginning
of a code line. In other programming languages
the indentation in code is for readability only, where as
the indentation in Python is very important.
Python uses indentation to indicate a block of code or
used in block of codes.
E.g.1
if 3 > 2:
print(“Three is greater than two!") //syntax error due to
not indented
E.g.2
if 3 > 2:
print(“Three is greater than two!") //Indented so no
error
Token

Smallest individual unit in a program is known as token.

1. Keywords
2. Identifiers
3. Literals
4. Operators
5. Punctuators/Delimiters
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 identifiers: 9show,my.book,fname-lname
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
Literals
Escape sequence/Back slash character constants

#A backslash followed by three


integers will result in a octal
value:
txt = "\110\145\154\154\157"
print(txt)

Hello

#A backslash followed by an 'x'


and a hex number represents a
hex value:
txt = "\x48\x65\x6c\x6c\x6f"
print(txt)

Hello
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
Operators
Operators can be defined as symbols that are used
toperform operations on operands.
Types of Operators
1. Arithmetic Operators.
2. Relational Operators/Comparison Operator
Relational Operators are used to compare the
values.
3. Augmented Assignment Operators
Used to assign values to the variables.
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
5. Bitwise Operators
2’s complement of 5
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 Precedence
Highest precedence to lowest precedence table. Precedence is used
to decide ,which operator to be taken first for evaluation when two
or more operators comes in an expression
Punctuators/Delimiters
Used to implement the grammatical and
structure of a Syntax. Following are the python
punctuators.
Barebone of a python program
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.
Variables
Concept of L Value and R Value in variable
Lvalue and Rvalue refer to the left and right side of
the assignment operator. The Lvalue (pronounced: L
value)concept refers to the requirement that the operand on
the left side of the assignment operator is modifiable,
usually a variable. Rvalue concept fetches the value of the
expression or operand on the right side of the
assignment operator.
example: amount = 390
The value 390 is pulled or fetched (Rvalue) and stored into
the variable named amount (Lvalue); destroying the
value previously stored in that variable.
Dynamic typing
Constants
A constant is a type of variable whose value cannot be changed. It is
helpful to think of constants as containers that hold information which
cannot be changed later. In Python, constants are usually declared and
assigned in a module. Here, the module is a new file containing
variables, functions, etc which is imported to the main file. Inside
the module, constants are written in all capital letters and underscores
separating the words.
Input and Output
print() Function In Python is used to print output on the screen.
Syntax of Print Function - print(expression/variable)
e.g.
print(122)
Output :-
122 print('hello India') Output :-
hello India
print(‘Computer',‘Science')
print(‘Computer',‘Science',sep=' & ')
print(‘Computer',‘Science',sep=' & ',end='.')

You might also like