0% found this document useful (0 votes)
26 views111 pages

Class8 Strings List DataType Combine

Uploaded by

memu00133
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)
26 views111 pages

Class8 Strings List DataType Combine

Uploaded by

memu00133
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

IDE - Integrated Development Environment

10 + 20

30

Types of cells
1 - Code cell
2 - Mark down cell

print("Hello")

Hello

10+20

10+20

30

cell 1

cell 2

cell 3

cell 4

cell 5

Heading1
Heading2
Heading3
Heading4
- This is python class
Python
• Point1
– Subpoint1
– Subpoint2
• Point2
• point1
– Subpoint1
– Subpoint2
Programming Language
• Programming Language is the way of communication between Humans and Machines

Python
• Python is a, High level , general purpose, Dynamically typed Programming language
Levels of programming languages
1 - High level -----> More understandable by Humans ----> ex:- Python,
Scala, Java , C++,R ,JS, C#
2 - Low level -----> More understandable by Machines-----> ex:-
Assembly language
3 - Middle level language -----> It is understandable by humans as
well as Machines ----> ex :- C

High level

general purpose (Multipurpose)


Python
DS
ML
DL
LLM
web apps
websites

Typed Programming languages


1 - Dynamically typed
2 - Statically typed

embedded C

10 + 50

60

NC ,
CNC
print("Hello")

Hello

java (Statically typed)

int a
a = 50

python (Dynamically typed)

a = 50

int a
a = 50

Cell In[11], line 1


int a
^
SyntaxError: invalid syntax

a = "X"
b = 30.333333
c= 10

'X'
b

30.333333

10

Interpretted Language or Compiled Language

a = 10
b = 20
# c = 30
d = 40

Is Python Interpretted language or Compiled language ?


Python is both interpretted as well a Compiled Language

10

20

----------------------------------------------------------------------
-----
NameError Traceback (most recent call
last)
Cell In[6], line 1
----> 1 c

NameError: name 'c' is not defined

40

a = 10
b = 20
c = 30
d = 40
print(a)
print(d)
print(c)
print(b)

10
40
30
20

Why Python ?
- Easy to learn or understand
- Open Source
- Vast Libraries ( numpy , Pandas , Scikit lear Scipy , Django , flask
Streamlit....)
- OOPs
- Multi purpose
- Community Support
- can connect to DBs
- Testing
- Cross Platform compatability Mutiple OS (Window , Mac IOS , Linux)

a = 10
var = 60

extensions of a python file


.py ----> anywhere
.ipynb ----> certain evns

# Executing a python file


1 - Normal execution in Jupyter
2 - Python Interpretor using terminal
3 - .py file using the terminal

a = 10
b = 20
c = a+b
print(c)

30

pwd

'C:\\Users\\Lenovo\\Desktop\\7 April 2025'

import sys
sys.path[0]

'C:\\Users\\Lenovo\\Desktop\\7 April 2025'


# Components of python
- Literals
- Constants
- identifiers
- reserved words / Keywords
- Statements and Expressions
- Block and indentation
- Comments

numpy

Literals
• literals are the values that you see in python
• int
• float
• str
• complex
• bool
• None
a = 10
b = "Hello"
c = 44.777

Constants
• the values tha can not be changed mathematically
• python - Use UPPER case variables to represent the constants
PI = 3.14 # do not change the value as it is a Constant
G = 9.81 # gravity constant do not change it

PI

3.14

pi = 3.14

PI = 500

PI

500

ABC = 55
abc = 98
abc

98

Java script
const a = 500;

gravity_constant

# identifiers/variable

• it is the name given to a literal


abc = 88
abc -----> varibale/ Identifier
88 ----> literal

cdf = 500
cdf -----> variable
500 -----> literal

# rules to declare a Identifier


- allowed char are A-Z , a-z , 0-9 , _
- can not start with a number
- it can not have numbers only
- Special caharacter are not allowed apart from (_)
- It should not have Space in between
- identifiers are case sensitive
- Should not use Reserved words

abc = 700

ABC = 900

abc

700

ABC

900

PTDDYython = 99
PTDDYython

99

lmn123 = 55.8888
lmn123

55.8888

_ = 100
_

100

lmslmslms = 99

lmslmslms

99

7086989687 = 90

Cell In[17], line 1


70 = 90
^
SyntaxError: cannot assign to literal here. Maybe you meant '=='
instead of '='?

var70 = 90

var70

90

abc123 = 80000

342abc = 900000

Cell In[21], line 1


342abc = 900000
^
SyntaxError: invalid decimal literal

$% = 543

Cell In[22], line 1


$% = 543
^
SyntaxError: invalid syntax

@ = 0

Cell In[25], line 1


@ = 0
^
SyntaxError: invalid syntax

_ = 40

_
40

my var = 200

Cell In[26], line 1


my var = 200
^
SyntaxError: invalid syntax

my_var = 200

LMN = 99
lmn = 77

LMN

99

A = 100

a = 60

60

# Reserved words / Keywords


- There are certain words in python that are defined to do a certain
task

print = 90

print

90

print("Hello")

----------------------------------------------------------------------
-----
TypeError Traceback (most recent call
last)
Cell In[35], line 1
----> 1 print("Hello")

TypeError: 'int' object is not callable

for
if

import keyword
dir(keyword)

['__all__',
'__builtins__',
'__cached__',
'__doc__',
'__file__',
'__loader__',
'__name__',
'__package__',
'__spec__',
'iskeyword',
'issoftkeyword',
'kwlist',
'softkwlist']

print(keyword.kwlist)

['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await',


'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except',
'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is',
'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try',
'while', 'with', 'yield']

None = 100

Cell In[3], line 1


None = 100
^
SyntaxError: cannot assign to None

print(dir(__builtins__))

['ArithmeticError', 'AssertionError', 'AttributeError',


'BaseException', 'BaseExceptionGroup', 'BlockingIOError',
'BrokenPipeError', 'BufferError', 'BytesWarning', 'ChildProcessError',
'ConnectionAbortedError', 'ConnectionError', 'ConnectionRefusedError',
'ConnectionResetError', 'DeprecationWarning', 'EOFError', 'Ellipsis',
'EncodingWarning', 'EnvironmentError', 'Exception', 'ExceptionGroup',
'False', 'FileExistsError', 'FileNotFoundError', 'FloatingPointError',
'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError',
'ImportWarning', 'IndentationError', 'IndexError', 'InterruptedError',
'IsADirectoryError', 'KeyError', 'KeyboardInterrupt', 'LookupError',
'MemoryError', 'ModuleNotFoundError', 'NameError', 'None',
'NotADirectoryError', 'NotImplemented', 'NotImplementedError',
'OSError', 'OverflowError', 'PendingDeprecationWarning',
'PermissionError', 'ProcessLookupError', 'RecursionError',
'ReferenceError', 'ResourceWarning', 'RuntimeError', 'RuntimeWarning',
'StopAsyncIteration', 'StopIteration', 'SyntaxError', 'SyntaxWarning',
'SystemError', 'SystemExit', 'TabError', 'TimeoutError', 'True',
'TypeError', 'UnboundLocalError', 'UnicodeDecodeError',
'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError',
'UnicodeWarning', 'UserWarning', 'ValueError', 'Warning',
'WindowsError', 'ZeroDivisionError', '__IPYTHON__', '__build_class__',
'__debug__', '__doc__', '__import__', '__loader__', '__name__',
'__package__', '__spec__', 'abs', 'aiter', 'all', 'anext', 'any',
'ascii', 'bin', 'bool', 'breakpoint', 'bytearray', 'bytes',
'callable', 'chr', 'classmethod', 'compile', 'complex', 'copyright',
'credits', 'delattr', 'dict', 'dir', 'display', 'divmod', 'enumerate',
'eval', 'exec', 'execfile', 'filter', 'float', 'format', 'frozenset',
'get_ipython', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex',
'id', 'input', 'int', 'isinstance', 'issubclass', 'iter', 'len',
'license', 'list', 'locals', 'map', 'max', 'memoryview', 'min',
'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property',
'range', 'repr', 'reversed', 'round', 'runfile', 'set', 'setattr',
'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple',
'type', 'vars', 'zip']

Statements and Expressions


a = 500 # statement

b = 700 + 99 # expression

# Block and indentation

Block
few lines of code together are called block

# indentation - space
space after the condition(:) in between is indentation

a = 100
b = 500
if a==100:
print("Begining of the block")
print("a value is 100")
print("b value is 500")
print("End of the block")
print("Out of the block")

Begining of the block


a value is 100
b value is 500
End of the block
Out of the block

a = 100
b = 500
if a==200:
print("Begining of the block")
print("a value is 100")
print("b value is 500")
print("End of the block")
print("Out of the block")

Cell In[16], line 5


print("a value is 100")
^
IndentationError: unexpected indent

if(i=0;i<=10;i++)
{codeline1
code2
code
}

for i in lst:
print()

def fun():
code

Comments (#)
• Comments are lines of code to write the explaination
# Why comments?
- Explain the code
- Makes code more redable
- Prevent the execution of the unnecessary code lines

a = 100 # a is declared 100


b = 700 # b is declared 700
c = 600 # c is declared 600
# d = 100
E = 900 # E is a Constant

----------------------------------------------------------------------
-----
NameError Traceback (most recent call
last)
Cell In[19], line 1
----> 1 d

NameError: name 'd' is not defined


a = 100
b = 700
c = 600
d = 10
E = 900

"""
This is a
Multiline Comment
We are writing
in multiline
comments
"""
a = 10

10

Data Types in python


• 1 - Fundamental Datatypes / Primitive data types
– int
– float
– bool
– complex
– str
– None
• 2 - Derived Data types / non primitive data types
– list
– tuple
– dict
– set
– frozenset

int
• integers are positive or negative numbers without decimal points (whole numbers)
a = 99

99

b = 0
b

type(a)

int

type(b)

int

c = -99999

type(c)

int

float
• floating point numbers are positive or negative numbers with decimal points
var = 99.001

var

99.001

type(var)

float

f = -60000.00000
type(f)

float

print(type(f))

<class 'float'>

operations on numbers
# Arithmetic operations
(+)-----> addition
(-)-----> Sbtraction
(*)-----> multiplication
(/)-----> float division (it gives decimal value)
(//)-----> floor division( it gives int value)
(%)-----> modulus
(**)-----> exponent

a = 10
b = 20

# addition
10 + 20

30

a + b

30

c = a + b
c

30

# Subtraction
10 - 20

-10

a -b

-10

b - a

10

# Multiplication (*)
a * b

200

a = 14
b = 3

Float division

10/5

2.0

# floor division

10//5

14/3
4.666666666666667

# floor value <--------------- 4.666666666666667---------------->ceil


value

floor value = 4

2.234358

floor = 2

ceil = 3

import math

math.ceil(4.666666666666667)

round(4.666666666666667)

math.ceil(4.666666666666667 , 2)

----------------------------------------------------------------------
-----
TypeError Traceback (most recent call
last)
Cell In[55], line 1
----> 1 math.ceil(4.666666666666667 , 2)

TypeError: math.ceil() takes exactly one argument (2 given)

round(4.666666666666667 , 2)

4.67

# % modulus
Remainder

3)14(4 ----> quotient -----> divisoin


12
---------
2 ------> remainder ---> modulus

14%3

10%5

0
# power/ Exponent (**)

4**10

64

4*4*4

64

pwd

'C:\\Users\\Lenovo\\Desktop\\7 April 2025'

type()

math.ceil(-4.88)

5
Comparision operation
- Comparision operators return Only a boolean value (True or False)
< # less than
<= # lessthan or equals
> # greater than
>= # greater than or equals

< # less than

a = 10
b = 99

10

99

a < b

10 < 99

True

b < a

False

<= # lessthan or equals

100 < 100

False

100 <= 100

True

> # greater than

10

99

a > b
False

b > a

True

>= # greater than or equals

100.99 > 100.99

False

100.99 >= 100.99

True

Equality operation
# Equality operators return Only a boolean value (True or False)

== # equals
!= # Not equals

1000 == 1000

True

200 == 400

False

10

99

a == b

False

a != b

True

str1 = "Hello"
str2 = "hello"

str1
'Hello'

str2

'hello'

str1 != str2

True

str3 = "hello"
str4 = "hello"

str3

'hello'

str4

'hello'

str3 == str4

True

# ASCII- American Standard Code for Information Interchange


"Hello"
"hello"

72

104

False

"hello"
"hello"

104,101 , 108 , 108 ,111

104 , 101 , 108 , 108 ,111

True

"A"

type()

# to check ASCII value from a letter


ord("A")

65

99

# to char value from a ASCII number

print(chr(99))

ord("s")

115

Logical operators
True ----> 1
False ---> 0

and
or
not

and
False and False
False and True
True and False
True and True

False and False

False

False and True

False

True and False

False

True and True

True

a = 100
b = 500
if a==100 and b==500: # True
print("Begining of the block")
print("a value is 100")
print("b value is 500")
print("End of the block")
print("Out of the block")

Begining of the block


a value is 100
b value is 500
End of the block
Out of the block

True and True

True
a = 100
b = 500
if a==100 and b==99: # False
print("Begining of the block")
print("a value is 100")
print("b value is 500")
print("End of the block")
print("Out of the block")

Out of the block

True and False

False

or

False or False
False or True
True or False
True or True

False or False

False

False or True

True

True or False

True

True or True

True

not
not True

False

not False

True

a = 5
not a > 3

False

a > 3

True

not True

False

Assignment Operation
= # assignment operator

a = 500

500

Compound operators
i++ Increment operator
i-- Decrement operator
a = 5

a = a+1 # a+=1

5+1

a = a+1 # a+=1

a = a-5 # a-=5
a

a+=8

10

a = 5
a = a+5 # a+=5
a = a-5 # a-=5
a = a*5 # a*=5
a = a/5 # a/=5
a = a//5 # a//=5
a = a%5 # a%=5
a = a**5 # a**=5

Identity operator
# it will check the addresses
# It will retur True or False only
- is
- is not

a = 10
b = 20
c = 30
print(a)
print(b)
print(c)
print(d)

10
20
30

----------------------------------------------------------------------
-----
NameError Traceback (most recent call
last)
Cell In[64], line 7
5 print(b)
6 print(c)
----> 7 print(d)

NameError: name 'd' is not defined

----------------------------------------------------------------------
-----
NameError Traceback (most recent call
last)
Cell In[65], line 1
----> 1 d

NameError: name 'd' is not defined

d =

Cell In[66], line 1


d =
^
SyntaxError: invalid syntax

Memory Reusability / Object reusability


a = 10
b = 10

id(a)

140733536545496

id(b)
140733536545496

limitations of Memory Reusability


it is applicable on integers (-5 to 256)
Memory reusability is not applicable on float
Memory reusability is not applicable on complex
Memory reusability is applicable on boolean
Memory reusability is applicable on None

var1 = 550
var2 = 550

id(var1)

2714025093488

id(var2)

2714025090928

var1 = -1
var2 = -1
print(id(var1))
print(id(var2))

140733536545144
140733536545144

var1 = 256
var2 = 256
print(id(var1))
print(id(var2))

140733536553368
140733536553368

# Memory reusability is not applicable on complex


a = 1+2j
b = 1+2j
print(id(a))
print(id(b))

2714025089776
2714025091408

a = True
b = True
print(id(a))
print(id(b))
140733535419264
140733535419264

a = None
b = None
print(id(a))
print(id(b))

140733535500240
140733535500240

a = 50
b = 50
print(id(a))
print(id(b))

140733536546776
140733536546776

a is b

True

var1

256

var2

256

abc = 1.002
lmn = 1.002
print(id(abc))
print(id(lmn))

2714004205104
2714025093232

abc is lmn

False

abc is not lmn

True

a = 50
b = 50
print(id(a))
print(id(b))
140733536546776
140733536546776

print (id(a) is id(b))

False

address_a = id(a)

address_b = id(b)

print(address_a is address_b)

False

print(140733536546776 is 140733536546776)

True

<>:1: SyntaxWarning: "is" with 'int' literal. Did you mean "=="?
<>:1: SyntaxWarning: "is" with 'int' literal. Did you mean "=="?
C:\Users\Lenovo\AppData\Local\Temp\ipykernel_3816\3745895525.py:1:
SyntaxWarning: "is" with 'int' literal. Did you mean "=="?
print(140733536546776 is 140733536546776)

id(140733536546776)

2714025092720

id(140733536546776)

2714025092528

a=5
b=10
Complex Number
any number that can be represented in the form of a+bj
where
a -----> Real number
b -----> Imaginary number

c = 5+4j

type(c)

complex

d = 99-100J
type(d)

complex

d.real

99.0

d.imag

-100.0

----------------------------------------------------------------------
-----
NameError Traceback (most recent call
last)
Cell In[10], line 1
----> 1 j**2==1

NameError: name 'j' is not defined

# Operations on Complex numbers


Arithmetic operation
Logical operation
Assignment operation
Identity operation
equality operation

# can no perform
Comparision operation
Arithmetic operation(% modulus operation and floor division)

a = 40 +39J
b = 5+1J
a

(40+39j)

(5+1j)

a + b

(45+40j)

a > b

----------------------------------------------------------------------
-----
TypeError Traceback (most recent call
last)
Cell In[15], line 1
----> 1 a > b

TypeError: '>' not supported between instances of 'complex' and


'complex'

a = 40 +39J
c = 40 +39J

print(id(a))
print(id(c))

1710943534800
1710943533552

a is c

False

a is not c

True

a % c

----------------------------------------------------------------------
-----
TypeError Traceback (most recent call
last)
Cell In[21], line 1
----> 1 a % c

TypeError: unsupported operand type(s) for %: 'complex' and 'complex'

a // b
----------------------------------------------------------------------
-----
TypeError Traceback (most recent call
last)
Cell In[23], line 1
----> 1 a //b

TypeError: unsupported operand type(s) for //: 'complex' and 'complex'

10+5J == 10+5j

True

None Type
• None is used to represent Missing values
a = None

type(a)

NoneType

Boolean data
True (1)
False (0)

1+1

True + True

1 + True

1 + False

int(True)
1

int(False)

False

False

Type Casting
• Changing one data type to other data type is type casting
a = 5.008653
type(a)

float

int(a)

5.008653

float_to_int = int(a)

float_to_int

str1 = "2.23345"

str1

'2.23345'

type(str1)

str

int(str1)

----------------------------------------------------------------------
-----
ValueError Traceback (most recent call
last)
Cell In[45], line 1
----> 1 int(str1)
ValueError: invalid literal for int() with base 10: '2.23345'

str1

'2.23345'

int(float(str1))

int(float(str1))

str2 = "22"
str_to_int = int(str2)
str_to_int

22

type(str_to_int)

int

str2 = "abc22"
str_to_int = int(str2)
str_to_int

----------------------------------------------------------------------
-----
ValueError Traceback (most recent call
last)
Cell In[54], line 2
1 str2 = "abc22"
----> 2 str_to_int = int(str2)
3 str_to_int

ValueError: invalid literal for int() with base 10: 'abc22'

a = 10
float(a)

10.0

complex(a)

(10+0j)

bool(a)

True

bool(None)
False

bool(700)

True

bool("Hello")

True

bool("")

False

a = 40 +39J
str(a)

----------------------------------------------------------------------
-----
ValueError Traceback (most recent call
last)
Cell In[74], line 2
1 a = 40 +39J
----> 2 float(str(a))

ValueError: could not convert string to float: '(40+39j)'

a.real

40.0

int(a.real)

40

Strings
string is a data type

anything written inside


'' ----> Single quotes
"" ----> double quotes
''' ''' ----> Single triple quotes
""" """ ---> Double triple quotes

a = 'Hello we are in python class'

a
'Hello we are in python class'

type(a)

str

a = 'Hello we are in python's class'

Cell In[80], line 1


a = 'Hello we are in python's class'
^
SyntaxError: unterminated string literal (detected at line 1)

a = "Hello we are in python's class"


a

"Hello we are in python's class"

a = "Hello we are in python"s class"


a

Cell In[84], line 1


a = "Hello we are in python"s class"
^
SyntaxError: unterminated string literal (detected at line 1)

a = '''Hello we are in python"s class'''


a

'Hello we are in python"s class'

W_S = ''' William Shakespeare[a] (c. 23[b] April 1564 – 23 April 1616)
[c] was an English playwright, poet and actor.
He is widely regarded as the greatest writer in the English language
and the world's pre-eminent dramatist.
He is often called England's national poet and the "Bard of Avon" (or
simply "the Bard"). His extant works,
including collaborations, consist of some 39 plays, 154 sonnets, three
long narrative poems and a few other verses,
some of uncertain authorship. His plays have been translated into
every major living language and are performed more often than
those of any other playwright. Shakespeare remains
arguably the most influential writer in the English language, and his
works continue to be studied and reinterpreted.'''

print(W_S)

William Shakespeare[a] (c. 23[b] April 1564 – 23 April 1616)[c] was


an English playwright, poet and actor.
He is widely regarded as the greatest writer in the English language
and the world's pre-eminent dramatist.
He is often called England's national poet and the "Bard of Avon" (or
simply "the Bard"). His extant works,
including collaborations, consist of some 39 plays, 154 sonnets, three
long narrative poems and a few other verses,
some of uncertain authorship. His plays have been translated into
every major living language and are performed more often than
those of any other playwright. Shakespeare remains
arguably the most influential writer in the English language, and his
works continue to be studied and reinterpreted.

W_S = """ William Shakespeare[a] (c. 23[b] April 1564 – 23 April 1616)
[c] was an English playwright, poet and actor.
He is widely regarded as the greatest writer in the English language
and the world's pre-eminent dramatist.
He is often called England's national poet and the "Bard of Avon" (or
simply "the Bard"). His extant works,
including collaborations, consist of some 39 plays, 154 sonnets, three
long narrative poems and a few other verses,
some of uncertain authorship. His plays have been translated into
every major living language and are performed more often than
those of any other playwright. Shakespeare remains
arguably the most influential writer in the English language, and his
works continue to be studied and reinterpreted."""

print(W_S)

William Shakespeare[a] (c. 23[b] April 1564 – 23 April 1616)[c] was


an English playwright, poet and actor.
He is widely regarded as the greatest writer in the English language
and the world's pre-eminent dramatist.
He is often called England's national poet and the "Bard of Avon" (or
simply "the Bard"). His extant works,
including collaborations, consist of some 39 plays, 154 sonnets, three
long narrative poems and a few other verses,
some of uncertain authorship. His plays have been translated into
every major living language and are performed more often than
those of any other playwright. Shakespeare remains
arguably the most influential writer in the English language, and his
works continue to be studied and reinterpreted.

type(W_S)

str

W_S

' William Shakespeare[a] (c. 23[b] April 1564 – 23 April 1616)[c] was
an English playwright, poet and actor.\nHe is widely regarded as the
greatest writer in the English language and the world\'s pre-eminent
dramatist.\nHe is often called England\'s national poet and the "Bard
of Avon" (or simply "the Bard"). His extant works,\nincluding
collaborations, consist of some 39 plays, 154 sonnets, three long
narrative poems and a few other verses,\nsome of uncertain authorship.
His plays have been translated into every major living language and
are performed more often than \nthose of any other playwright.
Shakespeare remains\narguably the most influential writer in the
English language, and his works continue to be studied and
reinterpreted.'

'hello this is python"s class'

'hello this is python"s class'

a = 'Hello we are in pythons class'

'Hello we are in pythons class'

a = 'Hello we are in
pythons class'

Cell In[99], line 1


a = 'Hello we are in
^
SyntaxError: unterminated string literal (detected at line 1)

a = '''Hello we are in
pythons class'''

print(a)

Hello we are in
pythons class

Input Output functions


Task - take 2 variables assign some int value
and get the sum of those two numbers

a = 10
b = 20
a+b

30

input()
- it is a function to get the user input from the end user
a = input("Enter the first number ")
b = input("Enter the Second number ")

Enter the first number 10


Enter the Second number 20

type(a)

str

type(b)

str

Task - take 2 values as user input


and get the sum of those two numbers

a = input("Enter the first number ")


b = input("Enter the Second number ")

Enter the first number 70


Enter the Second number 30

# type casting
a = input("Enter the first number ")
b = input("Enter the Second number ")
a = int(a)
b = int(b)
a+b

Enter the first number 10


Enter the Second number 30

40

a + b

'7030'

"Hello" + "World"

'HelloWorld'

# type casting
a = float(input("Enter the first number "))
b = float(input("Enter the Second number "))
a+b

Enter the first number 20


Enter the Second number 30

50.0
a

20.0

30.0

10
10.0

eval

a = eval(input("Enter the first number "))


b = eval(input("Enter the Second number "))
a+b

Enter the first number "Hello"


Enter the Second number 2+3j

print(type(a))
print(type(b))

<class 'str'>
<class 'complex'>

a = eval(input("Enter the first number "))


b = eval(input("Enter the Second number "))
print(type(a))
print(type(b))

Enter the first number 10


Enter the Second number 20.55

<class 'int'>
<class 'float'>

c = input("Enter the first number ")


d = input("Enter the Second number ")
print(type(c))
print(type(d))

Enter the first number 10


Enter the Second number 20.55

<class 'str'>
<class 'str'>

Output Function
print()
help(print)

Help on built-in function print in module builtins:

print(*args, sep=' ', end='\n', file=None, flush=False)


Prints the values to a stream, or to sys.stdout by default.

sep
string inserted between values, default a space.
end
string appended after the last value, default a newline.
file
a file-like object (stream); defaults to the current sys.stdout.
flush
whether to forcibly flush the stream.

print("hello")

hello

print(20000)

20000

a = 10
b = 20
c = 30
print(a , end="$$$")
print(b)
print(c)

10
20
30

'\n"
New line

10$$$20
30

a = 10
b = 20
c = 30
print(a , end="@@@\n")
print(b)
print(c)
10@@@
20
30

10@@@
20
30

a = 10
b = 20
c = 30
print(a,b,c , sep=" ")

10 20 30

a = 10
b = 20
c = 30
print(a,b,c , sep="-----------------")

10-----------------20-----------------30

a = 10
b = 20
c = 30
print(a,b,c , sep="\n")

10
20
30

10
20
30

a = 10
b = 20
c = 30
print(a )
print(b)
print(c)

print
print
print
print
print
print
print
print
a = 10
b = 20
c = 30
print(a,b,c , sep="\n")
print(a)

10
20
30
10
format String
first_name = "Jhon"
last_name = "Usman"
# "My first name is Mohammed and my last name is Usman"

print("My first name is",first_name ," and my last name is


" ,last_name)

My first name is Jhon and my last name is Usman

1st way - f""

first_name = "Mohammed"
last_name = "Usman"
print(f"My first name is {first_name} and my last name is
{last_name}")

My first name is Mohammed and my last name is Usman

num1 = eval(input("Enter the first Number: "))


num2 = eval(input("Enter the second Number: "))
print(f"Entered number one is {num1} and the second number is {num2}
and the sum both the numbers is {num1 + num2}")

Enter the first Number: 55


Enter the second Number: 60

Entered number one is 55 and the second number is 60 and the sum both
the numbers is 115

# 2- way .format()

num1 = eval(input("Enter the first Number: "))


num2 = eval(input("Enter the second Number: "))
print("Entered number one is {} and the second number is {} and the
sum both the numbers is {}".format(num1, num2 , num1+num2))

Enter the first Number: 10


Enter the second Number: 20

Entered number one is 10 and the second number is 20 and the sum both
the numbers is 30

"first number is {b} and another is {a} and sum is {c}


".format(a=num1, b=num2, c=num1+num2)

'first number is 20 and another is 10 and sum is 30 '

balance = 5000
debit = int(input("Enter the amount you want to withdraw: "))
final_balance = balance-debit
print(f"You have withdrawn {debit} and the remaining balance is
{final_balance}")

Enter the amount you want to withdraw: 1000

You have withdrawn 1000 and the remaining balance is 4000

balance = 5000
debit = int(input("Enter the amount you want to withdraw: "))
print(f"You have withdrawn {debit} and the remaning balance is
{balance-debit}")

Enter the amount you want to withdraw: 200

You have withdrawn 200 and the remaning balance is 4800

balance = 5000
debit = int(input("Enter the amount you want to withdraw: "))
final_balance = balance-debit
print(f"You have withdrawn {debit} and the remaning balance is
{final_balance}")

Enter the amount you want to withdraw: 6000

You have withdrawn 6000 and the remaning balance is -1000

String Properties
• Strings are sequence data types , which means indexing and slicing is possible

a = "python"
b = "cython"

# Memory reusability is Applicable on strings


print(id(a))
print(id(b))

2575070231792
2575075316128

a is b

False

Indexing and Slicing


Indexing
- Extracting a char from a string is indexing

1 - Positive indexing
- positive indexing starts from 0 and it goes from L to R
2 - Negative Indexing
- negative indexing starts from -1 and it goes from R to L

a = "python"

syntax

var_name[index_number]

# o from +ve index


a[4]
'o'

# o from -ve index


a[-2]

'o'

# t
a[2]

't'

a[-4]

't'

a = "python"
b = "cython"

a[3]

'h'

b[3]

'h'

id(a[3])

140733553581968

id(b[-3])

140733553581968

Slicing
1- Positive Slicing
2 - Negative Slicing

a[-12:-1:-1]

''
a = "lionel messi"

syntax
var_name[start_index:stop_index:step]
stop----> exclusive

# ion
# +ve
a[1:4:]

'ion'

# mess
a[7:11:]

'mess'

# messi
a[7:12:]

'messi'

a[7::]

'messi'

# -ve Slicing

var_name[start_index:stop_index:step]

a[-10:-7:]

'one'

# lion
# +ve
a[0:4:]
'lion'

# -ve
a[-12:-8:]

'lion'

# messi
a[-5::]

'messi'

# step
a[::]

'lionel messi'

start ----> 0
stop ---> end of the str
step-----> +1 ( L to R)

a[-12:-8:1]

'lion'

a[-12:-8:1]

'lion'

a[-12:-8:-1]

''

a[2:6:1]

'onel'

a[2:6:-1]

a[::]

'lionel messi'

a[0:12:2]

'loe es'

# reverse a string
a[11::-1]

'issem lenoil'

a[::-1]

'issem lenoil'
a[::-2]

'ismlni'

a[0:12:3]

'ln s'

a[::]

'lionel messi'

a[::-1]

balance=500
debit=int(input("enter the amount you want to withdraw: "))
final_balance = balance-debit
print(f"you have withdraw{debit} and the remaining balanceis
{final_balance}")

enter the amount you want to withdraw: 1000

you have withdraw1000 and the remaining balanceis -500


# Immutable (Not Changable in acutual string variable)

a = "Wednesday"
"Sednesday"

a[6::] = "way"

----------------------------------------------------------------------
-----
TypeError Traceback (most recent call
last)
Cell In[46], line 1
----> 1 a[6::] = "way"

TypeError: 'str' object does not support item assignment

a[0] = "S"

----------------------------------------------------------------------
-----
TypeError Traceback (most recent call
last)
Cell In[49], line 1
----> 1 a[0] = "S"

TypeError: 'str' object does not support item assignment

# Mutable data type


l = [100 , 200 , 300 , 400 , 500]
l[0]

100

l[0] = 9000

[9000, 200, 300, 400, 500]

String Operations
# Indexing
# Slicing
# Concatination
# Identity
# Membership Operation
Concatination (+)
• joining two or more strings is concatination
a = "We are"
b = " Learning "
c = "Python"

a+b+c

'We are Learning Python'

# Identity (is , is not)

a = "Wednesday"
b = "Wednesday"

print(id(a))
print(id(b))

1735102526960
1735102526960

a is b

True

id(a) is id(b)

a is not b

False

str1= "Hello"
str2 = "Hello"

str1 is str2

True

addr_str1 = id(str1)

addr_str1

1735150816880

addr_str2 = id(str2)

addr_str1 is addr_str2

False
Membership Operation (in , not in)
str1 = "Usman loves to play football"

str1

'Usman loves to play football'

"football" in str1

True

"Cricket" in str1

False

"Cricket" not in str1

True

"l" in str1

True

"F" in str1

False

string methods
Methods are functions that are defined in a class

'Wednesday'

print(type(a))

<class 'str'>

print(dir(str))

['__add__', '__class__', '__contains__', '__delattr__', '__dir__',


'__doc__', '__eq__', '__format__', '__ge__', '__getattribute__',
'__getitem__', '__getnewargs__', '__getstate__', '__gt__', '__hash__',
'__init__', '__init_subclass__', '__iter__', '__le__', '__len__',
'__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__',
'__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__',
'__sizeof__', '__str__', '__subclasshook__', 'capitalize', 'casefold',
'center', 'count', 'encode', 'endswith', 'expandtabs', 'find',
'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isascii',
'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric',
'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust',
'lower', 'lstrip', 'maketrans', 'partition', 'removeprefix',
'removesuffix', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition',
'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip',
'swapcase', 'title', 'translate', 'upper', 'zfill']

# capitalize()
s = "this is python"

'this is python'

s.capitalize()

'This is python'

'this is python'

# upper()

s = "this is python"

s_upper_case = s.upper()

s_upper_case

'THIS IS PYTHON'

# lower()

s = 'THIS IS PYTHON'

s.lower()

'this is python'

# swapcase()
lower to upper
upper to lower

"apple BANANA".swapcase()

'APPLE banana'

# The methods which return bool values

startswith()
s = "Python is a programming language"

s.startswith("P")

True

s.startswith("Z")

False

s.startswith("Python")

True

# endswith()

s.endswith("Z")

False

s.endswith("e")

True

s.endswith("guage")

True

isalpha
isnumeric
isalnum

# isalpha - True for alphabets and false for other char


s1 = "abc" # True
s2 = "123abc" # False
s3 = "$$$$" # False
s4 = "121323" # False
print(s1.isalpha())
print(s2.isalpha())
print(s3.isalpha())
print(s4.isalpha())

True
False
False
False

# isnumeric - True for numbers and false for other char


s1 = "abc" # false
s2 = "123abc" # False
s3 = "$$$$" # False
s4 = "121323" # True
print(s1.isnumeric())
print(s2.isnumeric())
print(s3.isnumeric())
print(s4.isnumeric())

False
False
False
True

# isalnum - True for if the string contains alphabet or number false


otherwise
s1 = "abc" # True
s2 = "123abc" # True
s3 = "$$$$" # False
s4 = "121323" # True
print(s1.isalnum())
print(s2.isalnum())
print(s3.isalnum())
print(s4.isalnum())
s5 = "हिंदी"
print(s5.isalnum())

True
True
False
True
False

# isascii
# isalnum - True for if the string is having an ASCII value false
otherwise
s1 = "abc" # True
s2 = "123abc" # True
s3 = "$$$$" # True
s4 = "121323" # True
s5 = "हिंदी" # False
print(s1.isascii())
print(s2.isascii())
print(s3.isascii())
print(s4.isascii())
print(s5.isascii())

True
True
True
True
False
# islower()
s = "hello"
s.islower()

True

s = "Hello"
s.islower()

False

# isupper()

s = "hello"
s.isupper()

False

s = "HELLO"
s.isupper()

True

strip
rstrip
lstrip

strip()

s = " Welcome "

' Welcome '

s.strip()

'Welcome'

s = "************Welcome**************"
s.strip("*")

'Welcome'

# rstrip()
s = " Welcome "
s.rstrip()

' Welcome'

s = "************Welcome**************"
s.rstrip("*")

'************Welcome'
# lstrip()
s = " Welcome "
s.lstrip()

'Welcome '

s = "************Welcome**************"
s.lstrip("*")

'Welcome**************'

input("Enter the Password: ")

Enter the Password: Password

' Password'

"Welcome".strip("Wle")

'com'

find
rfind
index
rindex

# find() - it give the index number of first occurance of the


specified char or group of char from L to R

s = "Usman c loves to play chess"


s.find("c")

# rfind - it give the index number of first occurance of the specified


char or group of char from R to L
NOTE - it only gives positive index number only

s = "Usman c loves to play chess"


s.rfind("c")

22

s = "nUsman"
s.find("n")

s = "nUsnman"
s.rfind("n")

6
# index() - it give the index number of first occurance of the
specified char or group of char from L to R

s = "Usman c loves to play chess"


s.index("c")

# rindex - it give the index number of first occurance of the


specified char or group of char from R to L
NOTE - it only gives positive index number only

s = "nUsnman"
s.rindex("n")

# difference between find() and index()

s = "Football"

s.find("Z")

-1

s.index("Z")

----------------------------------------------------------------------
-----
ValueError Traceback (most recent call
last)
Cell In[111], line 1
----> 1 s.index("Z")

ValueError: substring not found

ljust - leftadjustment
rjust - rightadjustment

Indian

a = "Indian"

a.ljust(30)

'Indian '

30
6
24

a.ljust(30 , "*")

'Indian************************'
a.rjust(30)

' Indian'

split()
join()

split() ---> converts a sting to a list


NOTE - delimiter by default is " "

s = "Usman loves to play chess"

'Usman loves to play chess'

s.split()

['Usman', 'loves', 'to', 'play', 'chess']

s = "Usman@loves@to@play@chess"
s.split("@")

['Usman', 'loves', 'to', 'play', 'chess']

l = s.split("@")
l

['Usman', 'loves', 'to', 'play', 'chess']

join() - convert a list to a string

" ".join(l)

'Usman loves to play chess'

"@".join(l)

'Usman@loves@to@play@chess'

print(list(s))

['U', 's', 'm', 'a', 'n', '@', 'l', 'o', 'v', 'e', 's', '@', 't', 'o',
'@', 'p', 'l', 'a', 'y', '@', 'c', 'h', 'e', 's', 's']

replace
count

# replace - it replaces old char to new char

s = "Usman loves to play chess"


s.replace("chess" , "football")

'Usman loves to play football'


new_str = s.replace("chess" , "football")
new_str

'Usman loves to play football'

count()

new_str

'Usman loves to play football'

new_str.count("o")

a = "hello" # Immutable
b = [500 , 600 ,300] # mutable

a[0]

'h'

a[0] = "D"

----------------------------------------------------------------------
-----
TypeError Traceback (most recent call
last)
Cell In[141], line 1
----> 1 a[0] = "D"

TypeError: 'str' object does not support item assignment

b[0]

500

b[0] = -1000

[-1000, 600, 300]

s = "Usman@loves@,to@play@chess"
s.split("@,")

['Usman@loves', 'to@play@chess']

s="I love to play football"


s.replace("I love to play football", "I love to play chess")

'I love to play chess'

s
'I love to play football'

s = "Usman loves to play chess"


s.split()

['Usman', 'loves', 'to', 'play', 'chess']

l = ['Usman', 'loves', 'to', 'play', 'chess']

['Usman', 'loves', 'to', 'play', 'chess']

" ".join(l)

'Usman loves to play chess'

a = "lionel messi"

a[1: :-1]

'il'

a[1: :1]

'ionel messi'
print(dir(str))

['__add__', '__class__', '__contains__', '__delattr__', '__dir__',


'__doc__', '__eq__', '__format__', '__ge__', '__getattribute__',
'__getitem__', '__getnewargs__', '__getstate__', '__gt__', '__hash__',
'__init__', '__init_subclass__', '__iter__', '__le__', '__len__',
'__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__',
'__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__',
'__sizeof__', '__str__', '__subclasshook__', 'capitalize', 'casefold',
'center', 'count', 'encode', 'endswith', 'expandtabs', 'find',
'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isascii',
'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric',
'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust',
'lower', 'lstrip', 'maketrans', 'partition', 'removeprefix',
'removesuffix', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition',
'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip',
'swapcase', 'title', 'translate', 'upper', 'zfill']

"abC".swapcase()

help(str.swapcase)

Help on method_descriptor:

swapcase(self, /) unbound builtins.str method


Convert uppercase characters to lowercase and lowercase characters
to uppercase.

Special Char / Escape char in Strings


# "\n" ----> new line char

print("Hello\nWorld")

Hello
World

Hello
World

# backslash ---> \

"Hello\nWorld"

"Hello'\n'World"

print("Hello\nWorld")
Hello
World

print("Hello\\nWorld")

Hello\nWorld

a = 10
b = 20
print(a)
c = 40
print(c)

10
40

# \b ----> backspace

print("pqr\b\bstuv")

pstuv

pqstuv

# \r------> carriage return

print("Hello\rIndian")

Indian

H -----> I
e -----> n
l -----> d
l -----> i
o -----> a
n

print("Indian\rHello")

Hellon

I-----> H
n----->e
d----->l
i----->l
a----->o
n

print("Indian\rHello")

len("Indian")

len("Hello")

print("India\rHello")

Hello

print("Madhangi\r prakash")
# prakash

prakash

len("Madhangi")

len("prakash")

# \t -----> tab

print("Java\tPython")

Java Python

# r"" ---> raw string

print("Hello\nWorld\nWe are learning\nPython")

Hello
World
We are learning
Python

print("Hello\\nWorld\\nWe are leaning\\nPython")

Hello\nWorld\nWe are leaning\nPython

print(r"Hello\nWorld\nWe are leaning\nPython")

Hello\nWorld\nWe are leaning\nPython


Calculating length of a string
s = "Hello all we are learning python"
len(s)

32

len("chandana")

s.count("a")

ls

Volume in drive C has no label.


Volume Serial Number is 6CE9-051B

Directory of C:\Users\Lenovo\Desktop\7 April 2025

17-04-2025 20:42 <DIR> .


17-04-2025 20:42 <DIR> ..
17-04-2025 20:10 <DIR> .ipynb_checkpoints
08-04-2025 22:21 30 abc.py
07-04-2025 22:38 4,889 Class1_anaconda_installation.ipynb
08-04-2025 22:31 38,247 Class2_Intro_to_programming.ipynb
10-04-2025 22:41 78,815 Class3_Components_of_python.ipynb
10-04-2025 22:39 288,184 Class4_Operations_in_python.ipynb
14-04-2025 22:33 77,514 Class5_data_types.ipynb
15-04-2025 22:38 632,027 Class6_String_part1.ipynb
16-04-2025 23:00 91,871
Class7_String_operantions_Methods.ipynb
17-04-2025 20:42 22,482 Class8_Strings_list_dataType.ipynb
08-04-2025 22:04 17 demo.py
08-04-2025 22:21 0 name.py
14-04-2025 20:02 291,571 Screenshot.png
08-04-2025 22:16 13 untitled.py
13 File(s) 1,525,660 bytes
3 Dir(s) 162,151,415,808 bytes free

pwd

'C:\\Users\\Lenovo\\Desktop\\7 April 2025'

list
• list is a derived datatype
• homogenous or hetrogenous data in [] is a list
lst = ["Hello" , 1,2,3,4,5]

lst

['Hello', 1, 2, 3, 4, 5]

type(lst)

list

Creating a list
# 1 you know the elements already

lst1 = ["banana" , "mango" , "apple"]

lst1

['banana', 'mango', 'apple']

# 2 Taking input from the user

lst2 = eval(input("Enter a list: "))

Enter a list: [100,200,500]

lst2

[100, 2000, 300, 400]

eval(input("Enter the amount you want to withdraw"))

Enter the amount you want to withdraw 1000

1000

# 3 - Type Casting

str1 = "Hello World"

lst3 =list(str1)
lst3

['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd']

# 4 - split()

lst4 = str1.split()
lst4

['Hello', 'World']
Properties of list
• list is a sequence data type , indexing and slicing is allowed
• Mutable
• It can contain homogenous or hetrogenous data or both
• it allows duplicate
• operations -----> Concatination , Repetition , Identity, Membership
lst = [100,200,300,700,900 ,500]

[]

# Indexing
- +ve
- -ve

# extract 700
lst[3]

700

lst[-3]

700

lst[4]

900

lst[-2]

900

# slicing

lst = [100,200,300,700,900 ,500 , 800 , 600 , 700]

[700,800,900,300,100]

lst[-1: :-2]

[700, 800, 900, 300, 100]

lst[8::-2]

[700, 800, 900, 300, 100]

# Mutablility

lst = [100, 200, 300, 700, 900, 500, 800, 600, 700]

lst[5] = 10000

lst
[100, 200, 300, 700, 900, 10000, 800, 600, 700]

lst_homo = [100, 200, 300, 700, 900, 500, 800, 600, 700]
# --- int ------> homgenous data

lst_hetro = [100, 200,2.2 , 3+7j , "Hello World", 600, 700]


# ---- hetrogenous data type

lst_homo

[100, 200, 300, 700, 900, 500, 800, 600, 700]

lst_hetro

[100, 200, 2.2, (3+7j), 'Hello World', 600, 700]

lst_dup = [10 ,10 ,10,10,10,10,10]

lst_dup

[10, 10, 10, 10, 10, 10, 10]

operations on list
# Concatination , Repetition , Identity, Membership

(+)

lst

[100, 200, 2.2, (3+7j), 'Hello World', 600, 700]

lst

[100, 200, 2.2, (3+7j), 'Hello World', 600, 700]

print(lst + lst)

[100, 200, 2.2, (3+7j), 'Hello World', 600, 700, 100, 200, 2.2,
(3+7j), 'Hello World', 600, 700]

[1,2,3] + [4,5,6]

[1, 2, 3, 4, 5, 6]

Repetition (*)

op1 ---> int


op2 ---> list
operator ---> *

[1,2,3] * 5
[1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]

"Hello" * 3

'HelloHelloHello'

# Identity

lst1 = [1,2,3,4]
lst2 = [1,2,3,4]

print(id(lst1))

2231367745216

print(id(lst2))

2231347778240

id(lst1[0])

140733550307768

id(lst2[0])

140733550307768

lst1 is lst2

False

lst1[0] is lst2[0]

True

lst1[0] is not lst2[0]

False

# Multiply 5 to each element


lst = [1,2,3,4,5]
l = []
for i in lst:
l.append(i*5)

[5, 10, 15, 20, 25]

# Membership (in , not)


lst = [1,5,6,200,900,"hello" ,"thanos" , "Iron man" , 3.55]

lst

[1, 5, 6, 200, 900, 'hello', 'thanos', 'Iron man', 3.55]

900 in lst

True

"Iron man" in lst

True

"3.55" in lst

False

3.55 in lst

True

nested list
# list inside a list is a nested list

nested_list = [100 , 200 , 400 , [5,4,9,0.7]]

nested_list[2]

400

nested_list[3]

[5, 4, 9, 0.7]

nested_list[3][3]

0.7

nested_list = [100 , [200], 400,[99,[487,88,76,["Thor" , "Hulk" , 86 ,


[55, 77,64, "Avengers"]]]] , [5,4,9,0.7]]

"Avengers"

print(nested_list)

[100, [200], 400, [99, [487, 88, 76, ['Thor', 'Hulk', 86, [55, 77, 64,
'Avengers']]]], [5, 4, 9, 0.7]]

nested_list[3]

[99, [487, 88, 76, ['Thor', 'Hulk', 86, [55, 77, 64, 'Avengers']]]]
nested_list[3][1]

[487, 88, 76, ['Thor', 'Hulk', 86, [55, 77, 64, 'Avengers']]]

nested_list[3][1][3]

['Thor', 'Hulk', 86, [55, 77, 64, 'Avengers']]

nested_list[3][1][3][-1]

[55, 77, 64, 'Avengers']

nested_list[3][1][3][-1][-1]

'Avengers'

# Bitwise operations

& ----> bitwise and


| ----> bitwise or
^ ----> bitwise XOR
<< ----> bitwise left shift
>> ----> bitwise right shift
~ ----> bitwise not / negate

10 & 4

bin(10)

'0b1010'

1010

bin(4)

'0b100'

100

1 0 1 0
0 1 0 0
and
----------------
0000

0b0000

# | ----> bitwise or

44 | 56
60

bin(44)

'0b101100'

bin(56)

'0b111000'

1 0 1 1 0 0
1 1 1 0 0 0
or
---------------
1 1 1 1 0 0

0b111100

60

# ^ ----> bitwise XOR

44 ^ 56

20

1 0 1 1 0 0
1 1 1 0 0 0
XOR
---------------
0 1 0 1 0 0

0b010100

20

Q1. Declare an int value and store it in a variable.


Check the type and print the id of the same.

(1+2j) / (2+2j)

(0.75+0.25j)

You might also like