CBSE CS and IP

CBSE Class 11 & 12 Computer Science and Informatics Practices Python Materials, Video Lecture

Showing posts with label Class 11 CS. Show all posts
Showing posts with label Class 11 CS. Show all posts

Cyber Law IT ACT 2000

CYBER LAW


What is cyber Law?


  • Cyber law, also known as cybercrime law, is legislation focused on the acceptable behavioral use of technology including computer hardware and software, the internet, and networks.
  • Cyber law helps protect users from harm by enabling the investigation and prosecution of online criminal activity.
  • It applies to the actions of individuals, groups, the public, government, and private organizations.

Overview of Indian IT ACT

  • The Information Technology Act, 2000 (also known as ITA-2000, or the IT Act) is an Act of the Indian Parliament notified on 17 October 2000. It is the primary law in India dealing with cybercrime and electronic commerce.
  • A major amendment was made in 2008 and now it is called the IT (Amendment) Act 2008.

Some Suggested questions that may be asked in board examination Class 12 CS/IP

  1. What is Cyber Crime? Write the act that deals with it.
  2. What is IT Act, 2000? Write down 2 salient features of IT Act, 2000.
  3. Difference between Cyber Crime and Cyber Law.

Class 11 Computer Science Video Lectures

String Data Type in Python

Strings in Python
String Definition / What Is Strings in Python?

Python string is characters/numbers/special characters enclosed in quotes of any type - single quotation marks (' '), Double quotation marks ( " ") and triple quotation marks (" " "). An empty string is a string that has 0 characters (i.e. it is just a pair of quotation marks) Python string is immutable. you have used string in earlier chapters to store text type of data.

Every character of the string is given a special number that is called its index position. Consider the following string:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
my_string = "Hello World"
print(my_string)
print(type(my_string))

'''
Output:
Hello World
<class 'str'>
'''

#Index Positions
# H   e  l  l  o  W  o  r  l  d
# 0   1  2  3  4  5  6  7  8  9 (Forward)
#-10 -9 -8 -7 -6 -5 -4 -3 -2 -1 (Backward)                         

By the above example, you can see that my_string is a variable of string type and all the characters of the string will have one unique index.

By now you must know that strings are a sequence of characters. where each character has a unique position - id/index. The index of a string begins from 0 and end on (length - 1) in the forward direction and -1,-2,-3....,-length in the backward direction. As in the example in the forward direction index are 0,1,2....,9 and in backward direction -1,-2,-3.....-10.

Accessing Individual elements of Python String

Since every elements has its Unique Index in Python we can access any element from string by just providing the Index in square brackets with string Name. See the following Example:
1
2
3
4
5
6
7
8
9
>>> my_string = "Hello World"                                      
>>> my_string[0]
'H'
>>> my_string[1]
'e'
>>> my_string[-1]
'd'
>>> my_string[-2]
'l'

Traversing A String -:

Traversing refers to iterating through the elements of a string, one character at a time. You know that individual characters of a string are accessible through the unique index of each character. Using the indexes you can traverse string character by character. We can traverse a string by using the for loop. You can write a loop like :
Example -:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
for i in "Hello World":                                            
     print(i)

'''
Output:
H
e
l
l
o

W
o
r
l
d
'''

String  Operators -:

You will be learning to work with various operators that can be used to manipulate strings in multiple ways. We will be talking about basic operators + and * membership operators in and not in and comparison operators (all relational operators) for strings.
  1.  Basic Operators
  2.  Membership Operators
  3.  Comparison Operators

(1) Basic Operators -: 

The two basic operators of the string are + and *. You have used these operators as arithmetic operators before for addition and multiplication respectively. But "+ operator" is used with string operands it performs "concatenation" rather than addition and "* operator" performs "replication" rather than multiplication.

Also before we proceed,  recall that strings and immutable i.e. and un-modifiable. Thus every time you perform something on a string that changes it Python will internally create a new string rather than modifying the old string in place.

a) Working Of Python * operators -:

The * operator, when used with numbers, (i.e.  When both your operands are numbers),  it performs multiplication and returns the product of the two number operands.

To use a * operator with string, you need to type of operands-:
(1) string
(2) number
It can be in the following forms:
number * string or string * number

Where string operands tell the String to be replicated and number operand tells the number of times, it is to be repeated. Python creates a new string that is a number of repeated addition of the string operator.
Example -:
1
2
3
4
5
6
>>> my_string = "Hello World"
>>> my_string * 3
'Hello WorldHello WorldHello World'
>>>
>>> 3 * my_string
'Hello WorldHello WorldHello World'                                

b) Working Of Python + Operators -:

This + operator has to either have both operands of the number types (for multiplication) or both should be of string type. It can not work with one operand string types and another as number type.
Example-:
1
2
3
4
5
6
>>> "Hello" + "World"
'HelloWorld'
>>> "Hello" + 2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can only concatenate str (not "int") to str             
In the above example, you can see we can not add One String and One number.

(2) Membership Operators -:

There are two membership operators for string (in fact for all sequence types). These are in and not in. Let us learn about these operators in the context of strings.

in         -: Returns TRUE if a character or a substring exists in the given string; FALSE otherwise
not in  -: Returns TRUE if a character or a substring does not exist in the given string; FALSE otherwise

both membership operators (when used with string), require that both operands used with them are of string type i.e.
Example-:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
>>> 'H' in 'Hello World'
True
>>> 'Y' in 'Hello World'
False


>>> 'H' not in 'Hello World'
False
>>> 'Y' not in 'Hello World'                                       
True

(3) Comparison Operators -:

Python standard comparison operators i.e. All relational operators (<,<=,>,>=, ==, !=)  apply to strings also. The comparisons using these operators are based on the Standard character by character comparison rules for Unicode (i.e. Dictionary order).

Equality and Non-Equality in strings are easier to determine because it goes for exact character matching for individual letters including the case (uppercase or lowercase) of the letter. 

But for another comparison like less than (<)  or greater than(>)  you should know the following piece of useful information. 
  • Python checks the Ordinal values while comparing String using (<, >, <=, >=).
  • You can find the ordinal value of any char by using ord(<char>) function. Find the characters and their ordinal values(ASCII values):
    Characters Ordinal Values
    ‘0’ to ‘9’ 48 to 57
    'A’ to ‘Z’ 65 to 90
    ‘a’ to ‘z’ 97 to 122
  • Ordinal values are compared character by character.
Example-:
1
2
3
4
5
6
7
'a'  <  'A'             False
'A'  >  'a'		True
'ABC' > 'AB'	        True
'abc' <=  'ABCD'	False                                      
'abc' < 'Acd'	        False
'abc' > 'Acd'	        True
'abcd'> 'A'	        True	

Cyber Safety And Security (CBSE Class 11)

cyber safety and security class 11 cbse
What is cyber safety/Internet Safety?

Today's age cannot be thought without the Internet, even in dreams. Nowadays every person is being a victim of online fraud. Mostly children are caught in this trap so the first thing we need to know is how to protect a child from online fraud? The government has started its cyber safety and security lesson for the 11th class. So that children can avoid online fraud. For this, the parents have to be aware of and follow the tips of cyber safety. Although the internet has made many things easier at the same time it has posed many security risks too, if not used properly.
Cybersafety refers to the safe and responsible use of the internet to ensure the safety and security of personal information and not posing threat to anyone else information.

Top 5 Cyber Crime Safety And Security Tips -:

Here we will discuss some cyber security and safety tips that will let us know how to prevent cyber crime? and learn more solutions to cyber crime. we mention some tips:-
  1. identity protection while using the internet
  2. many ways website track you 
  3. Confidentiality of information and strong password
  4. Avoid using public computers
  5. Carefully handles Emails

1) Identity Protection While Using The Internet -:

Identity theft is a type of fraud that involves using someone else's identity to steal money or gain other benefits.when we give out private data like filling up some forms, online payment, then they can be used for harmful reasons like hacking, stalking, and identity fraud.
A most common solution to this private browsing like incognito browsing opens up a browser that will not track your activities. If you are entering data like bank detail into the browser.

2) Many Ways Websites Track You -:

Whenever you visit a website, your web browser may reveal your location via your device's IP address. It can also provide your search and browsing history etc. Which may be used by third parties, like advertised or criminal. This way website tracks you. This generally includes -:

-IP Address -: IP address is a unique address of your device when you connect to the internet.it's likely that your computer shares your IP address with the other networked devices in your office. Your geographical location can be determined by your IP address, any website that you are accessing can determine your rough location.

-Cookies And Tracking Script -: Cookies are small pieces of information that a website can store in your browser. When you sign-in to your online banking website, a cookie remembers your login information. When you change a setting on a website, a cookie store that setting so it can persist across page loads and sessions. For example, you change the zoom percentage of your webpage then this setting will reflect on all opened pages because this was stored in cookies.

3) Confidentiality Of Information And Strong Password-: 

The Internet is a public platform. The sites you visit, the things you search on it, the posts that you put on social networking sites all visible to the public. But there must be some information like your credit history or bank details, your mail, etc. which you do not want to make public i.e. you want to keep this information confidential.
If you visited any website and fill forms like sign up, log in, personal, bank details, etc then you create a powerful password include capital letter alphabet, numeric symbols, etc. Due to a strong password,  your chances of getting hacked are less and your personal information is safe.

4) Avoid Using Public Computers -:

If you need to work on public computers then make sure following things -:
1) Don't save your login password.
2) Avoid entering sensitive information onto public computers.
3) Properly log out before you leave the computers.
4) Erase history and cookies.

5) Carefully Handles Email -:

While opening an email, make sure that you know the sender. even if you open the email message by accident, make sure not to open an attachment in an email from an unrecognized source. Also, your mail might contain a link to a legitimate-looking website, never click on any link inside an email. The link might look legit but it may take you to a fraudulent site. Even if you need to visit the linked website, type the URL of the website on your own in the address bar of a web browser but never open any link by clicking inside an email or by copying its link.

Comments (Single/Multiline) in Python

Comments (Single/Multiline) in Python


DataCamp

What is Comment in Python?

Any remark such as who made the code and the purpose in the form of a note can be added in the program using comments. Comments are not executed by the interpreter, they are added with the purpose of making the source code easier to understand by humans. The documentation of the code is done with the help of comments in the program itself. 

Comments are the additional readable information to clarify the source code, which is read by the programmers but ignored by the Python interpreter.

Why it is important to use Comments?

Whenever developers make a program, gradually so many codes are written in the same file for the different types of functionality. If commenting is not proper,  after some time, we do not understand our own code. We will face difficulty in understanding the codes written in our own program. So to easily understand the same problem, we use comments.
When you are working on a project with your team, it is necessary to use comments so that other programmers can understand what you have done in the source code by looking at the comment.
Using comments in our code makes our code easier to understand.

How do you write comments in code?

  • Comments are used to explain the code, which code is written for which work.
  • Comments are not part of the program, yet it is most useful for understanding the code.
  • Single line comments in Python begin with a symbol # (hash character) and generally end with the end of the physical line. (A physical line is the one complete line that you see on a computer whereas a logical line is the one that python sees as one full statement).
  • Multiline comments can be used in a program by simple put our text inside triple double-quotes (" " ") or triple single-quotes  (' ' '). Comments enclosed with triple quotes are called Docstring (Document String)

How many types of Comments?

Python has two types of comments, which are given below -:
  1. Single-Line Comments
  2. Multi-Line Comments

Single-Line Comments

In Python, Single line comments start with (#) symbol. 
If we put a # symbol at the starting of any line, then that line will be treated as a comment line. This line will not execute at the execution time, interpreter simply ignores it.
Example -: A single line comments in the program
# Single Line Comment
# Single Line Comment 

Multi-Line Comments

Multi-line comment in python code in two ways  -:
  1. Add a # symbol at the beginning of every physical line part of the multi-line comments.
  2. Type comment as a triple quoted multi-line string. This type of comment is also known as the docstring. You can either use a triple single-quote (' ' ') or triple double-quotes (" " ") to write a docstring. 
Example -: A Multi-line comments in the program
'''
This is a multiline Comment
This is a multiline Comment
This is a multiline Comment
'''
"""
This is a multiline Comment
This is a multiline Comment
This is a multiline Comment
"""


Benefits of using Comments in Python?

  1. The code can easily be understood when using comments.
  2. Makes code readable and understandable.
  3. Using Comments, we remember why we used this code.
  4. If the program is opened in the future, then there is no problem in understanding the code.
  5. Using comments gives the programmer an idea as to why they are using this code.


Data Types In Python

Data Types in Python

In this post, I am going to discuss various types of data that you can store in Python. The data can be stored in mutable or immutable types of variable.

Let us now discuss CBSE class 11 subject Informatics practices and Computer Science chapter Data Types in Python.

What is Data type?

A data type or simply a type is a property of data, that tells the language processor (compiler, interpreter) how we are going to use this data. 
  • Data types tell the meaning of data, how that data is going to store in memory and what different operations can be performed on it. 
  • In the Python programming language, if we have to store any value in a variable, then the data type role comes into play.
  • when we are storing a value in a variable, we have to use the same types of data as the type of variable. Each value belongs to some data type in Python.
  • Data type identifies the type of data which a variable can hold and the operations that can be performed on those data.

Mutable vs Immutable Data Types

Mutable:- Mutable data types are objects whose value can be changed once it is created. This type of object allows changing the value in place.
Ex:- List, Dictionary, Set
1
2
3
4
5
6
7
8
>>> v = 10
>>> type(v)
<class 'int'>
>>> id(v)
140731797110112
>>> v = 20
>>> id(v)
140731797110432                                                 

Immutable:- Immutable data types are objects whose value cannot be changed once it is created. 
Ex:- int, float, bool, string, tuple
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
>>> l = [1,2,3]
>>> type(l)
<class 'list'>
>>> id(l)
2413299978760
>>> l[0] = 99
>>> l
[99, 2, 3]
>>> id(l)
2413299978760                                                      

Data Types In Python -:

There are many data types available in python like character, integer, real, string, etc.

Before you learn how can process different types of data in Python, let us discuss various data types supported by Python. Everything in the Python programming language is an object, the data types are actually classes and variables are objects of these classes. 

Python offers the following built-in core data types -: 
  1. Numbers
  2. String
  3. List
  4. Tuple
  5. Dictionary
See the description of these data types in the following table:


S. No. Data types Description
1 Numbers Integer Number-:
-It is of unlimited range, which depends on the availability of memory.
-We can not use the Decimal number in it.
Example -: 5, 32, 1876,0
Boolean Value -:
Two value TRUE (1) / FALSE (0)
Floating Point Number -:
-It is of unlimited range, range depends upon the memory in the machine architecture.
-It is used to store a decimal number.
Example -: 5.0, 32.0
Complex Number -:
Same as floating-point numbers, because the real and imaginary parts are represented as floats.
Example-: A+Bj
2 String It is a sequence of Unicode characters.
It can hold any type of known characters, like letters, numbers.
It is a derived data type.
Example-: 'abcd', '1234', '????'
3 List It represents a list of comma-separated values of any datatype between square brackets.
It is a compound data types.
The list is changeable means one can change/add/delete the elements of a list.
Example -:[1, 2, 3, 4] ['a', 'b', 'c', 'd']
4 Tuple the tuple is immutable/non-changeable that means one can not make a change to a tuple.
Example :
p= (1, 2, 3, 4,5)
q = (2, 4, 6, 8)
r = ('a', 'b', 'c', 'd')
r = ('2', '5', '7', 'a', 'b', 'c')
5 Dictionary It is in an unordered set of comma-separated key: value pairs.
No two keys can be the same (unique keys within a dictionary).

The type() function is used to check the data type

Numbers

As it is clear by the name the number data types is used to store numeric values in Python, which means Number data type stores only numerical values.

When a number is assigned to a variable, then Python creates an object of Number Class.

Now, we will understand which numeric data type does Python support. We will tell you about it below -:
  1. Integer Numbers
  2. Boolean data type
  3. Floating Point Numbers
  4. Complex Numbers

Integer Numbers -:

  • Integers are whole numbers such as 2, 43, 2356, 0, etc.
  • They do not have any fraction parts. In Python, Integers are represented by numeric value with no decimal point.
  • Integers can be positive or negative. Positive numbers are represented with a + (plus) sign, and negative numbers are represented by - (minus) sign.
  • Integers in Python 3.x can be of any length, it is limited by the memory available. Python provides single data type integer to store an integer, whether big or small.
Example -:

## var1 is an integer variable
var1 = 10
type(var1)

##Output
<class 'int'>

Boolean Value -:

Just like in real life some questions are answered in yes or no, similarly, the computer also gives answers in yes or no. To store this type of value in a computer, we use boolean data type. A boolean value is represented by True or False.
  • It represents the value only in True and False.
  • The boolean type is a subtype of plain integers.
  • True and False behave like (1) and (0).
  • When user type bool(0) or bool(1), Then Python will return a value False and True respectively. bool(0) will always give False. Any number other than 0, weather +ve or -ve will give True if passed inside bool().
  • There is no conversion between the Boolean Data Type and Integer Data Type. 
  • We can directly use Boolean value True/False in any kind of conditional statement.
Example -:
## var1 and var2 is an boolean variable
var1 = True
type(var1)   ##Output: <class 'bool'>

var2 = False
type(var2)   ##Output: <class 'bool'>

Floating Points Number -:

If we have to declare the variables in our program which are to be used to stores decimal numbers, then we declare such variables as a float data type. 
  • A number which has some parts as fractional is called floating-point number.
  • The decimal point (i.e. a dot ".") signals that this number is a floating-point number, not an Integer.
  • Floating numbers can be positive or negative.
  • Floating points variables represent real numbers. Which are used for measurable quantities like distance, area, temperature, etc. and typically have a fractional part.
  • Floating numbers represent machine-level double precision floating point numbers (15 digit precision). 

Advantage-:

  • They can represent a value between the Integers.
  • We can represent a large range of values using it.

Disadvantage -:

  • Floating points operations are usually slower than integer operations.
Example -:
## var1 is a floating type variable
var1 = 5.75
type(var1)   ##Output: <class 'float'>

Complex Number -:

  • Python represents complex numbers as a pair of floating-point numbers.
  • A complex number is a composite quantity made of two parts -: the Real part and the Imaginary part. Both of which are represented internally as Float values (floating-point numbers).
  • A complex number consists of both real and imaginary components.
  • In complex number A + Bi. where  A is a real number and B is an imaginary part. i is used for denoting the imaginary part.
Example -:
## var1 is a complex data type variable
var1 = 3 + 5j
type(var1)   ##Output: <class 'complex'>

var1.real    ##Output: 5.0
var1.imag    ##Output: 3.0


String Data type

The string is written within a single(' ') or doubles (“ “) quotes.


When we provide information to the user, then the information is always represented as a group of characters, the group of characters is called String.

In Python 3.x, each character stored in a string is a Unicode character, which means all string in Python 3.x is a sequence of pure Unicode characters. Unicode is a system which is designed to represent every character from every language.


  • A string is the Group of characters. These characters may be digits alphabets or special characters including spaces.
  • A string data type lets you hold string data like any number, of valid characters into a set of quotation (" ")  marks.
  • A string can hold any type of known characters like letters, numbers, and special characters.
Following are string in python

'abcd' , '1234'

Example -:

## var1,var2,var3 are string data type variables

## with double quotes
var1 = "Hello"
type(var1)     ## <class 'str'>

## with single quotes
var2 = 'Hello'
type(var2)     ## <class 'str'>

var3 = '12345'
type(var3)     ## <class 'str'>




List Data type


A list is an important data type of Python. Many values are kept in it. Each value is separated by a comma, And all the values are placed inside a square bracket {'[', ']'}.

  • A list is a python compound data type. It can have different data types of data inside it.
  • Lists can be changed/modified/mutate. This means List is a Mutable Data type.
  • A list in python represents a comma-separated value of any datatype between the square bracket.
Example -:
## var1,var2,var3 are list data type variables

## with similar data type variables 
var1 = [1,2,3,4]
type(var1)     ## <class 'list'>

var2 = ['A','B','C','D']
type(var2)     ## <class 'list'>

## with different data type variables
var3 = ["Hello",1,2,3.5]
type(var3)     ## <class 'list'>


Tuples Data type

  • A tuple is a sequence of items separated by commas and items are enclosed in parenthesis { '(' and ')'}. This is unlike the list, where values are enclosed in square brackets {'[', ']'}.
  • The difference between List and Tuple is that the Tuples can not be changed or modified once created. That means we can not change items in the tuple. The similarity to a list is that the items of Tuples may be of different data types.
Example -:
## var1,var2,var3 are list data type variables

## with similar data type variables 
var1 = (1,2,3,4)
type(var1)     ## <class 'tuple'>

var2 = ('A','B','C','D')
type(var2)     ## <class 'tuple'>

## with different data type variables
var3 = ("Hello",1,2,3.5)
type(var3)     ## <class 'tuple'>


Dictionary

Tokens In Python


Tokens In Python



Tokens in Python -:

Today we will discuss "Python tokens", "Types of tokens with example", "List of tokens in Python", "How many types of tokens are allowed in Python".The Smallest individual unit in a python program is known as "Tokens".Python has mainly 5 types of token which are given below -:
  1. Keywords
  2. Identifiers
  3. Operators
  4. Literals 
  5. Punctuators 

Keywords in Python

What are the keywords in Python??

Keywords are the reserved word having special meaning and purpose in Python. Keywords cannot be used as an identifier name such as any variable name or Function Name. They are used to defined "Syntax" or "Structure" of the Python language. Python Keywords are case sensitive.

Python keywords is a special word, that forms the vocabulary of the python language. It is a reserved word that can not be used as an identifier.

How many keywords are there in Python??

There are as many as 33 keywords are used in Python programming language version 3.7. Keyword builds the vocabulary of the python language, they represent the "syntax and structure" of a python program.

How do you find a keyword in Python??

Following is the list of keywords in the python, there are 33 Keywords:

S No Keywords Description
1 and A logical operator
2 as To create an alias
3 assert For debugging
4 break To break out of a loop
5 class To define a class
6 continue It skips the remaining part of the loop and goes to the next iteration
7 def To define a function
8 del To delete an object
9 elif Used in conditional statements, same as else if
10 else Used in conditional statements
11 except It is used with exceptions. this part will execute if an exception occurs.
12 FALSE Boolean value, the result of comparison operations
13 finally It is used with exceptions. It executes irrespective of exception occurs or not
14 for To create a for loop
15 from To import specific parts of a module
16 global To declare a global variable
17 if To make a conditional statement
18 import To import a module
19 in To check if a value is present in a list, tuple, etc.
20 is To test if two variables are equal
21 lambda To create an anonymous function
22 None Represents a null value
23 nonlocal To declare a non-local variable
24 not A logical operator
25 or A logical operator
26 pass It is a "do nothing" statement. 
27 raise To raise an exception
28 return To exit a function and return a value
29 TRUE Boolean value, result of comparison operations
30 try To make a try...except statement
31 while To create a while loop
32 with Used to simplify exception handling
33 yield To end a function returns a generator
  

Identifier in Python

Before knowing Python Identifiers, we will learn what is Identity?? 

Identity is a property that makes a person different, it may be personality looks or expressions. Same way, Python identifier is the same as the identity of a Person.

Names given to a Class, Function or Variable is called Identifier in python. It helps to differentiate one entity from others.

What are the rules for identifiers??

  1. Identifier first letter should be any letter or underscore(_).
  2. Upper and lower-case letters are different.
  3. The digit 0 through 9  can be part of the identifier except for the first character.
  4. It should not be a keyword (list of 32 keywords discussed above).
  5. An identifier can not contain any special character except for underscore (_).

Valid / Invalid  Identifiers Examples -:

Valid Identifier -:  Mybook, file 123, z2td, _no
Invalid Identifier  -: 2rno , break , .mybook

Let us discuss why the given identifiers are Invalid.

  • 2rno: It is starting with a number
  • break: It is a Keyword
  • .mybook: It is containing "." keyword.  

Operators in Python

Operators are tokens that trigger some computation/action when applies to variables and other objects in an expression. Variables and objects to which the computation is applied are called operands.

There are following 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 performing arithmetic operations like Addition, Subtraction, Multiplication, division etc.
  • There are following types of Arithmetic Operators in Python:
    Operators Description Example
           + perform addition of two number a+b
            - perform subtraction of two number a-b
            / perform division of two number a/b
            * perform multiplication of two number a*b
            % Modulus = returns remainder a%b


Relational (Comparison )Operators -:

  • Relationa operators perform an operation on data and return the result in Boolean true or False.
  • Relational Operators are used to comparing the value and decide the relation among them.
 Operators Description Example
      == True if a is equal to b a == b
      != True is a is not equal to b, otherwise False a != b
       > True if a is greater than b, otherwise False a>b
      >= Greater than or equal to, return true if a is greater than b or a is equals to b a>=b
       < True if a is less than b, otherwise False a < b
     <= Less than or equal to, return true if a is less than b or a is equals to b a<=

Assignment Operators -:

  • Assignment Operators are used to assigning value to a variable.
  • There are following types of assignment operators are there in Python:
Operators Description Example
      = Right side value will be assigned to the left side. a=b
    += both the operands will be added and result will be assigned to the left side operand. a+=b
     /= left operand divided by right operand, the result will be assigned to the left side operand a/=b
     *= both the operands will be multiplied and the result will be assigned to the left side operand. A*=b
     -= left operand minus right operand, the result will be assigned to the left side operand A-=b
    %= left operand modulus right operand, the result will be assigned to the left side operand a%=b
    //= left operand floor divide right operand, the result will be assigned to the left side operand a//=b
   **= the left operand to the power of right operand, the result will be assigned to the left side operand. a**=b

Logical Operators -:

  • Logical operators are used with conditional statements that can be TRUE or False.
  • Logical Operators are used to performing logical operations on the two given variables or values.
  • and, or and not are logical operators.
Operators Description Example
    and return true if both conditions are true x and y
     or return true if either or both condition is true x or y
     not reverse the condition not(a>b)

Bitwise Operators -:

  • Bitwise Operators acts on operands as if they were string or binary digits. They operate bit by bit hence its name is bitwise Operator.
Operator Meaning Example
          & Bitwise AND x & y = 0 (0000 0000)
           | Bitwise OR x | y = 14 (0000 1110)
           ~ Bitwise NOT ~x = -11 (1111 0101)
           ^ Bitwise XOR x ^ y = 14 (0000 1110)
         >> Bitwise right shift x >> 2 = 2 (0000 0010)
        << Bitwise left shift x << 2 = 40 (0010 1000)

Membership Operators -:

  • The Membership operators are used to validate whether a value is found within a sequence such as string, lists or tuples.

  • Operators Description Example
          in return true if a value exists in the sequence, else false. a in list
       not in return true if the value does not exist in the sequence, else false. a not in list

Identity Operators -:

  • Identity operators are used to comparing the memory location 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


Literal (Value) in Python

  • Literals like a constant (often referred to as constant - values) are data items that have a fixed value.
  • Literals yields an object of the given type (String, integer, Long integer, Long floating number, Complex number ) with the given value.
    Python allows several kinds of literals.
    1. String Literals
    2. Numeric Literals
    3. Boolean Literals.

SN Literal Name Description
1 String Literal A string literal is a sequence of characters surrounded by quotes (single or double or triple quotes)
Example-: 'a' , 'abc' , "abc"
2 Numeric Literal 1. int (signed integers) -: No decimal points.
Example -: age=22
2. float (floating point real values) –: represent real number & written a decimal point.
Example -: height = 5.2
3. complex (complex numbers)
Example-: name = None
3 Boolean Literal 1. true (Boolean Literal)
2. false (Boolean Literal)

Punctuators  in Python

  • Punctuators is used to implement the grammar and structure of syntax. 
  • Punctuators are symbols that are used in a programming language to organize programming sentence.
The most common punctuators of Python programming language are:-  

| ' " # \ [ ] : ; =
( ) { } @ <<= >>= **= %= &=