RN Reddy Core Python
RN Reddy Core Python
Core Python
by
Mr.R.N Reddy
RN Reddy IT School
Online/Classroom Training’s
For more details
Phone: +91 9577146777, 9885199122
E-Mail: [email protected]
Visit: www.rnreddyitschool.co
FB Page: - www.facebook.com/Reddyitschool
RN Reddy IT School – Core Python
Q) What is a python?
A) Nothing
1. Data science
2. Data analytics
3. Machine learning
4. Deep learning
5. Artificial intelligence
6. Robotics
7. Big data mobile application
8. Data web application devotes
9. Testing
10. IOT ( internet of things)
Features of python
Python is a very easy programming language
Example :- In c # or java if you want to write single line code we should write within
the main method on the main method should be within the same class like below
Public class program
{
Static void main (string []args)
{
//code
}
}
But in python we don't require to write main method
Python code:-
Print(“hello”)
o/p :- hello
RN Reddy IT School – Core Python
Example:-
C# or java code :
Int a=10;
but in python we don't require to mention the data type and semi colon like below
a=10
print(a)
o/p = 10
Example 3 :-
In C# for Java will have multiple numerical data types as well as multiple floating point data types but in
python we have only numerical data type
i.e int 0 and only one floating data type i.e (float)
python code :-
a=10
print(type(a))
o/p = int
a=10.4
print(type(a))
o/p = float
Example:-
Functions
module 1
Classes
package 2 module 2
python
pakage
package 1 module 3
8) python is a dynamic type programming language programmer does not need to declare
any data type the data type will be taken automatically based on initialised value if we
initialise numerical value dynamically take as int
9) Python is interpreter based programming language
Python languages are two types
• Compiler based programming language
• Interpreter based programming language
RN Reddy IT School – Core Python
•In compiler in compiler best programming language •Example python in case of interpreter
program will get first compile once compilation is based programming language interpreter
completed entire program then only it will get execution engine will compile and
execute means here it will divide into two steps execute the code line by line like below
•Compilation doing compiler •Python interpreter program
•Execution is doing execution engine •line 1 ------->compile and execute
•Example for compiler based programming language •line 2 ------->compile and execute
c, c + +, Java, c# •line 3 ------->compile and execute
•In this process when we compile program it will •Observation in this casecode is compiling
produce collection of files which consume lot of and execution line by line due to that
memory for example if we compile c program it will reason it is not producing any supporting
produce following files files which will not consume more
•Object it will contain machine understandable code memory
•.exe it will contain executable code
•.bak(it will contain original program code as back up
•after compilation is compiled we will run .exe file for
execution
We can integrate python code into Java code as well as .net code
To integrate python code into Java code we have JYTHON http:// www.jython.org
Note:-
If you want to integrate python code into Java code we have to install Jython software , on
that software we should open Java application and we can write python code ,which will
convert as Java code by jython after this we can run this application on Java framework
RN Reddy IT School – Core Python
With this process it will open python program window write the below code
Print(“hello”)
o/p :- hello
Print(“hi”)
o/p :- hi
Print(“hello”)
o/p :- hello
Observation
In the above program it will giving line by line output which is used for only testing not be
useful for development due to that reason python will support two programming modes
Interactive mode
Batch mode
Interactive mode
how to open interactive mode
o/p :- hi
RN Reddy IT School – Core Python
IDLE
It will open
Here go to menu
Integrate python code into . Net code we have IRON pythonhttp://ironpython.net
NOTE:-
For this process first we have to install ironpython software and we have to open. Net
applications and we can write python code which will convert as .NET code by ironpython
finally we can run that application on.Net framework
It will open python code window we can write our program like below
>>>print(‘welcome to python’)
Print(“hi”)
Print(“hello”)
RN Reddy IT School – Core Python
File new file it will open new file write the code below
Print(‘welcome to python’)
Print(‘welcome to programming’)
welcome to programming
Write a python program to print one numerical value one floating value and one string value
10 (wrong method)
‘ ’ (correct method)
Q) What is a variable?
A) A field which represent some value which can be changed is called as variable
Example :-
A= 10
10
B = 20.5 20.5
C= ’rama’
rama
RN Reddy IT School – Core Python
Q) Write a python program to store a person ‘rama’ name into one variable called name and person
age 20 into another variable called age print these two values with the help of variables
Name rama
name='rama'
age=20
print(name)
print(age)
output :-
rama
20
Step 3 : Tracing
RN Reddy IT School – Core Python
Write a python program to store employee information i.e empno=111 empname=rama empsal=1000
into 3 variables they are empno ,empname and empsal print these three values with the help of
variables
output
empno 11
111
rama
1000
Step 3 : Tracing
RN Reddy IT School – Core Python
Q) Write a python program to store student information sid= 123 sname=rama sloc= Hyd into three
variables sid,sname,sloc print these three values with the help of 3 variables
output
sid 123
output :-
123
rama
hyd
RN Reddy IT School – Core Python
Step 3 : Tracing
RN Reddy IT School – Core Python
Q) Write a python program to store 3 subject marks 60, 70, 80 into three variables they are M1 M2 M3
calculate total marks Store into one variable called totmarks display the total marks with the help of a
message and variable
output
m1+m2+m3
total marks are: 210
Step 2 : program
m1=60
m2=70
m3=80
totmarks = m1+m2+m3
print('total marks are : ',totmarks)
output :-
Step 3 : Tracing:-
RN Reddy IT School – Core Python
Q) Write a python program three subject marks 60 70 80 into three variables M1 M2 M3 calculate total
marks store into one variable cal total marks and calculate average marks and store into another variable
called average marks print total marks and average marks with the help of messages and variables
output
m1+m2+m3
total marks = m1+m2+m3 total marks are : 210
Step 2 : program
=60+70+80 avg marks : 70
m1=60
m2=70 =210
m3=80 Avg marks= (m1+m2+m3)/3
totmarks = m1+m2+m3
avgmarks=(m1+m2+m3)/3 = 70
print('total marks are : ',totmarks)
print('avg marks are : ',avgmarks)
output :-
Step 3 : Tracing
RN Reddy IT School – Core Python
Q) write a python program to store two product 1000,2000 into two variables they are P1 P2 calculate
total bill store into one variable called total bill and calculate 10% discount on total bill and store
discount in disc variable display the total bill after discount by using messages and variable
p2=2000
Step 2 : program
totbill = p1+p2
p1=1000 =100+2000
p2=2000
totbill = p1+p2 =3000
disc=totbill*0.10 Disc = totbill*0.10
totalbill = totbill - disc
print('total bill is : ',totalbill) =300
Totbill = totbill-disc
output :-
=3000-300
total bill is : 2700.0
=2700
Step 3 : Tracing
RN Reddy IT School – Core Python
Q) Write a python program to store two product cost 1000,2000 into two variables they are P1 P2 and
calculate total bill store into to one variable called total bill on total bill calculate 20% discount and store
into one variable called disc after discount calculate 30% tax on total bill and display total bill with the
help of messages and varible
output
Step 1 : design with output
p1=1000 totbill is = 3120
p2=2000
totbill = p1+p2
p1=1000 =3000
p2=2000
Disc = totbill*0.20
totbill = p1+p2
disc=totbill*0.20 =600
totabill = totbill - disc
tax=totabill*0.30 Totbill = totbill-disc
totalbill=totabill+tax =3000-600
print('total bill is : ',totalbill)
=2400
=720
Totbill= totbill+tax
=2400+720
=3120
RN Reddy IT School – Core Python
Step 3 : Tracing
RN Reddy IT School – Core Python
Q) Write a python program to store 3 product costs 2000,3000, 4000 into three variables there P1 P2 P3
calculate total bil store into one variable called total bill on total bill 30% discount and 40% tax finally
display the total bill after discount and tax with the messages on wearable implement this by using four
steps
p2=3000
p3=4000
p1=2000 =2000+3000+4000
p2=3000
=9000
p3=4000
totbill = p1+p2+p3 Disc = totbill*0.30
disc=totbill*0.30
totabill = totbill - disc =2700
print('after discount total bill is : ',totabill) Totbill = totbill-disc
tax=totabill*0.40
totalbill=totabill+tax =9000-2700
print('total bill is : ',totalbill)
=6300
output :-
Tax = totbill*0.40
after discount total bill is : 6300.0
=2520
total bill is : 8820.0
Totbill= totbill+tax
=6300+2520
=8820
RN Reddy IT School – Core Python
Step 3 : Tracing
RN Reddy IT School – Core Python
Calculate total bill on total bill 30% discount after discount on total bill 40% tax finally display total bill
after tax
Step 2 : program
p1=1000
p2=2000
p1disc=p1*0.10
p2disc=p2*0.20
p1=p1-p1disc
p2=p2-p2disc
totbill=p1+p2
disc=totbill*0.30
totbill=totbill-disc
tax=totbill*0.40
totalbill=totbill+tax
print('total bill is :',totalbill)
OUTPUT :-
Write a python program to store to product cost 1000 ,2000 into two variables they are P1 and P2 on P1
10% discount and 20% tax on p to 20% discount on 30% tax calculate total bill and store into one variable
called total bill finally print total bill with messages and variable
Step 2 : program
p1=1000
p2=2000
p1disc=p1*0.10
p1=p1-p1disc
p1tax=p1*0.20
p1=p1+p1tax
p2disc=p2*0.20
p2tax=p2*0.30
p2=p2+p2tax
totbill=p1+p2
print('total bill is :',totbill)
output :-
RN Reddy IT School – Core Python
Step 3 : Tracing
Print ()
This method will print the given value
Type()
This method will return type of the given variable or value
ID()
This method will return variable address
For example :-
A=10 1234567890
Id=(a)
RN Reddy IT School – Core Python
They are:-
Int
Float
str
bool
complex
int :
In python we have only one numerical data types this data type represent a numerical
value which doesnot have any fractional point
Eno=524
Sid=58986
Float
Height=63.5
RN Reddy IT School – Core Python
Str:-
Collection of charcter which is enclosed with single quote , double quote , triple quote
B=’sita’
Bool:-
Bool represent either true value ore false valuetrue will be storing as binary 1 and false
will storing as binary 0
B=false---------0
Complex:-
This data type will not use in business application in we will use in scientific application
Type(a) 10+5j
A) converting from one data type to another data type is called type casting
int ()
float ()
string ()
bool()
complex()
int ()
int(‘rama’)
This method will convert the given value into int type a=10.5
o/p = error
int(true) int(‘10+5j’)
Example :-
a=10.5 o/p = 1 o/p = error
int(a) int(false)
int(20.3)
output = 10 o/p = 0
o/p = 20
Observation
Int() function will come not for all the types except complex type
Float
this method will convert the given any type value into float accept complex
float(true)
Example :- o/p = 1.0
float(false) float(‘10+5j’)
float(20) o/p = error
o/p = 0.0
o/p = 20.0
RN Reddy IT School – Core Python
Str():-
Observation:-
Bool()
bool(rama)
o/p = true
complex ()
Example:- Complex(‘rama’)
Q) write a python program to accept two numbers from the user and store into a and b perform addition
display addtion result
output:-
enter first number : 10
enter second number : 20
addition result: 30
step 3 :- Tracing
Q) write a python program to accept three subject marks M1 M2 M3 calculate the total marks and
average marks find the total marks and average marks
Output
step 1 :- Design with output
M1=60 enter m1 marks : 60
enter m1 marks : 60
enter m2 marks : 70
enter m3 marks : 80
total marks are: 210.0
average marks are: 70.0
Q) write a python program to accept two products cost b1 b2 calculate total bill on totalbill calculate 10%
discount display the total bill after discount
output
step 1 :- Design with output
P1=1000.0(using float) enter p1=1000
output:-
enter p1 : 1000
enter p2 : 2000
total bill is: 2700.0
step 3 :- Tracing
RN Reddy IT School – Core Python
Q) write a python program to accept two product cost P1 P2 and P1 10% discount and P2 20% discount
calculate total bill on total bill 30% tax display after discount and display tax finally display the total bill
after tax
step 3 :- Tracing
RN Reddy IT School – Core Python
Q) write a python program to accept two numbers and perform division and display the division result
step 1:-
program
output:-
5.0
For the above program if you have entered first numbers 10 second number zero is
throughing divide by zero error
Q) How to handle runtime error?
A) To handle runtime error with the help of logic we should go to the control statement
RN Reddy IT School – Core Python
Control statement
What we can do by using control statement using control statement we can control the
program according to our requirement
Whenever you want to go to control the program according to all in one requirement go
for control statement
Conditional statement
Loops
Transfer statement
Conditional statement
Q) What we can do by using conditional statement?
simple if
if else
if elif if
multiple if
nested if
simple if:-
<syntax>
If <condition>:
RN Reddy IT School – Core Python
output:-
if else:-
<syntax>
If <condition>:
Statement1
Else
Statement2
Q) Write a python program to compare i and j
output:-
RN Reddy IT School – Core Python
enter i value:6
enter j value:7
j is greaterthan i
if elif else:-
<syntax>
If <condition 1>:
Statement1
Elif<condition 2>:
Statement 2
Elif<condition 3>:
Statement2
Else
Statement4
Q) Comparing i and j by using if elif else
Output
Step 1:- design with output:
I=10 enter i value: 10
Step 2:- program
J=10 enter j value:10
i=int(input('enter i value:'))
j=int(input('enter j value:')) I is equal j
if i>j:
print('i is greaterthan j')
elif j>i:
print('j is greaterthan i')
else:
print('i is equal to j')
output:-
enter i value:10
enter j value:10
i is equal to j
Program:-
m1=int(input('enter m1 marks:'))
m2=int(input('enter m2 marks:'))
m3=int(input('enter m3 marks:'))
totmarks=m1+m2+m3
avgmarks=(m1+m2+m3)/3
if m1<35 or m2<35 or m3<35:
print ('result is fail')
elif avgmarks>=60:
print('result is first class')
RN Reddy IT School – Core Python
elif avgmarks>=50:
print('result is second class')
else:
print('result is third class')
output:-
enter m1 marks:54
enter m2 marks:54
enter m3 marks:84
MULTIPLE IF
<syntax>
If <condition 1>:
Statement1
If <condition 1>:
Statement1
Step 1 :- program
i=int(input('enter i value:'))
j=int(input('enter j value:'))
if i>j:
print('i is greaterthan j')
if i<j:
print('j is greaterthan i')
if i==j:
print('j is equal to i')
A) Whenever we have to option among two options if you want to execute one option
based on condition will go for if else
A) Whenever we have more than two option if you want to execute an option based on
condition will go for if elif
A) Whenever we have more than two option if you want to execute every option based on
one condition will go for multiple if
RN Reddy IT School – Core Python
Nested if
Implementing if else within if else or if with if else or if elif else with if else and so on is
called as nested if
i=int(input('enter i value:'))
j=int(input('enter j value:'))
if i>j:
print('i is greaterthan j')
else
if i<j:
print('j is greaterthan i')
else i==j:
print('j is equal to i')
Step 1 :- program
m1=float(input('enter m1 marks:'))
m2=float(input('enter m2 marks:'))
m3=float(input('enter m3 marks:'))
totmarks=m1+m2+m3
avgmarks=(m1+m2+m3)/3
if m1<35 or m2<35 or m3<35:
print ('result is fail')
else:
if avgmarks>=60:
print('result is first class')
elif avgmarks>=50:
print('result is second class')
else:
print('result is third class')
RN Reddy IT School – Core Python
Loops:-
What we can do by using loops using loops we can execute a single statement are multiple
statements more than one time.
A) Whenever you want execute a single statement on multiple statements more than one
time.
Types of loops
for loop
while loop
for loop with else
while loop with else
For loop :-
<SYNTAX>
Program
I output
for i in range(1,5): 1
print(i)
2
I output
Q) Write a python program to print 4 to 1 by using for loop
4
Program
3
for i in range(5,0,-1):
print(i) 2
1
RN Reddy IT School – Core Python
Program I output
for i in range(1,10): 1
if i%2!=0:
3
print(i)
5
I output
Program 20
for i in range(10,0,-1): 30
print(i)
40
50
I output
Q) Write a python program to print odd number like
10
Program
8
for i in range(10,0,-1):
6
if i%2!=0:
print(i) 4
While loop:-
<syntax>
While <condition>
<logic>
Q) Write a python program to print 1 to 4 by using for loop
Program I output
i=1 1
while i<=5:
print(i) 2
i=i+1 3
4
RN Reddy IT School – Core Python
Program I output
i=5 4
while i<=1:
print(i) 3
i=i-1 2
Program I output
program:- output
print(i,end=””)
Q) Write range (10): whenever we will give a single value for range function the range will take it is a
ending range but it will iterate ending range -1
print(i,end=””)
print(i,end=””)
Nested loop :-
Implementing loop within the loop is called as nested loop
1
Code: for i in range(1,6):
22 for j in range(i):
print(i,end="")
print()
333
4444
55555
RN Reddy IT School – Core Python
TRACING:-
22
Code:-
333
for i in range(1,8):
4444 for j in range(i):
print(i,end="")
print()
55555
666666
7777777
5 division result is 2
RN Reddy IT School – Core Python
1
Code:-
22
i=1
333 while i<=5:
j=1
while j<=i:
4444 print(i,end="")
j=j+1
55555 print()
i=i+1
55555 Code:-
4444 i=5
while i>=5:
333 j=1
while j<=i:
22 print(i,end="")
j=j+1
print()
1
i=i-1
Code:-
12345
i=5
1234 while i>=1:
j=1
while j<=i:
123 print(j,end="")
j=j+1
12 print()
i=i-1
1
12345
Code:-
1234
n=int(input('enter your range :'))
i=n
123 while i>=1:
j=1
12 while j<=i:
print(j,end="")
1 j=j+1
print()
i=i-1
RN Reddy IT School – Core Python
Q) Write a python program to print list of even numbers within the range
Q) Write a python program to check wheather the given number is prime or not
Step 1 :-
output
Step1:- design output
a enter a value: 10
Step 2:- program
b enter b value: 5
a=int(input('enter a value: '))
b=int(input('enter b value: ')) a value is 5
a,b=b,a
b value is 10
print('a value is ',a)
print('b value is ',b)
output:-
enter a value: 10
enter b value: 5
a value is 5
b value is 10
Output
Step1:- design output
Enter your string : rama
Step 2:- program
Reverse string: amar
str1=input('enter your string: ')
print('reverse string :', str1[::-1])
RN Reddy IT School – Core Python
Generally else part will be there for only conditional statements but in python else part is
available for loops
SYNTAX:-
//logic
Else
//logic
Note:- In this concept "for"block will execute as per number of iterations but "else" will
exit only one time in any case for loop is terminated by using break then else will not
execute
RN Reddy IT School – Core Python
Q) Write an Example to variable the atm pin by using for with else
Step :- programm
for i in range(1,4):
pin=int(input('enter your pin'))
if pin==1122:
print('valid pin')
break
else:
print ('you entered pin is wrong')
<syntax>
While<condition>
// logic
Else:
//logic
i=1
while i<=3:
pin=int(input('enter your pin'))
if pin==1122:
print('valid pin')
break
else:
print ('you entered invalidpin is your account is blocked')
Transfer statement
Using transfer statement we can transfer the program control from one place to another
place
RN Reddy IT School – Core Python
Break
Continue
pass
Break:-
Write a python program to print 1 to 10 numbers but output should be like below
output
for i in range(1,11):
print(i) 1
if i==6:
2
break
3
Q) When we will go for break?
4
A) Whenever we want to transfer control out of the loop 5
Continue:-
Step : program 2
i=8 4
for i in range(1,8):
if i==5: 6
continue
7
print(i)
RN Reddy IT School – Core Python
A) When our want to skip the current iterations then we will go for continue
Pass:-
String handling:-
Q) What is the difference between single double and triple quoted string?
A) Single quoted string and double quoted string with only single line but triple quoted
string will allow multiple lines.
Step:- program
output
str1=input('enter the string: ')
print('length of string is : ', len(str1)) Rama Enter the string:
For example :
str1=‟rama‟
print(len(str1))
output:
Isupper :- it will write letter in capital letter in full show true otherwise small letters will be
show false
For example :-
str1=‟rama‟
print(str1.isupper())
output:-
RN Reddy IT School – Core Python
true
Lower:- it will write small letter it will show true otherwise capital later it will show false
For example :-
str1=‟rama‟
print(str1.islower())
Output:-
false
Upper () :- it will write letters in small then it will convert capital letters
For example :-
str1=‟rama‟
print(str1.upper())
Output:-
RAMA
Lower:- it will written letters in capital or small then it will convert to small letters
For example :-
str1=‟rama‟
print(str1.lower())
output:-
rama
isalnum():- it will take alphabets and numerical values it will come true otherwise false
str1=’rama’
str1=‟123‟ print(str1.upper())
print(str1.isalnum())
output:-
True
output:-
True
Capitalize():- it will return first letter of the given string as a capital letter
For example :-
str1=‟rama‟
print(str1.capitalize())
RN Reddy IT School – Core Python
output:-
RAMA
Count:- it will return number of occurrence of a given character in a string
For example :-
str1=’rama’
print(str1.count(“a”))
output:-
2
Starts with () :- it will return the Boolean values and character it will check whether a
given character in starting letter or not
For example :-
str1=‟rama‟
print(str1.startwith(“r”))
output:-
True
Ends with ():- it will return the Boolean value it will set the weather given character is
ending letter or not
For example:-
str1=‟rama‟
print(str1.endswith(a))
output:-
True
For example :-
str1=‟rama‟
print(str1.find(m))
output:-
2
RN Reddy IT School – Core Python
output:-
………….rama………..
output:-
True
output:-
True
Index():- it will give the index value of a given character
For example :-
str1=‟rama‟
print(str1.index(“m”))
output:-
2
RN Reddy IT School – Core Python
Split():- it will Speed the given string into words and store it as an array with single quote
For example :-
str1=‟rama and sita‟
print(str1.upper())
output:-
[“rama” ,‟and‟,‟sita‟]
List
Tuple
Set
Frozenset
Dictionary
List:-
EXAMPLE of lists :-
Empnames=[“rama” ,‟and‟,‟sita‟]
Whenever we want to access an element of list you should access with the help of
index value like below
Empnames*0+ , will display ‘rama’
List is a mutable value
RN Reddy IT School – Core Python
A) A mutable object can be changed with this we can say list values can be changed
Example :- empnames*1+=’rani’
10 20 30 40 50 output
0 1 2 3 4
[10,20,30,40,50]
Step 2 :- code
mylist=[10,20,30,40,50]
print(mylist) output
10
Q) implement the above line by using loop
20
mylist=[10,20,30,40,50]
30
for I in mylist:
print(i) 40
50
Output
mylist=[10,20,30,40,50]
for I in mylist: [50,40,30,20,10]
print(:: , -1)
Accepting the number from the user and appending list and display
mylist=()
for i in range (1,6):
j=int(input('enter a number: '))
mylist.append(j)
print(mylist)
step2:- Tracing
Step1:- program
mylist=()
for i in range (1,6):
j=int(input('enter a number: '))
mylist.append(j)
print('mylist elements are : ')
for i in mylist:
print(i,end='')
step2:- Tracing
RN Reddy IT School – Core Python
For example :-
mylist=[10,20,30,40,50]
print(mylist.index(10))
Output:-
10
Eval():- This method will accept the elements from the user and store it into a list
For example :-
Output:-
input = [10,20,30,40,50]
[10,20,30,40,50]
NOTE:- eval() will convert the accepted value into list format
Append():- This method will be adding given element as last element to the list collection
For example :-
mylist=[10,20,30,40,50]
mylist.append(60)
print(mylist)
output:-
[10,20,30,40,50,60]
Extend():- This method will insert the multiple elements to the list at the time at last
For example :-
mylist=[10,20,30,40]
mylist.extend([40,50,60,70])
print(mylist)
output:-
[10,20,30,40,50,60,70]
RN Reddy IT School – Core Python
For example :-
mylist=[10,20,30,40,50]
mylist.remove(60)
print(mylist)
output:-
[10,20,30,40,50]
For example :-
mylist.pop()
print(mylist)
print(„pop elements based on index : , mylist.pop(2))
output:-
[10,20,30,40,50]
For example :-
mylist=[10,20,30,40,50]
dell mylist[1:3]
print(mylist)
output:-
[10, 30 ,50]
RN Reddy IT School – Core Python
For example :-
mylist=[10,20,30,40,50]
mylist.reverse()
print(„reverse elements are: „ , mylist)
output:-
For example :-
mylist=[10,20,30,40,50]
mylist.sort()
print(„sorted elements are: „ , mylist)
output:-
For example :-
mylist=[10,20,30,40,50]
mylist.copy()
print(„copied elements are: „ , mylist)
output:-
list1=[10,50,20,25,40]
list2=[100,10,2000,30,40]
mylist=list1+list2
print(mylist) #concatination
print(list1==list2) #comparision
mylist=[100,200,300,400,[500,600,700]] #nestedlist
print(mylist)
output:-
[10, 50, 20, 25, 40, 100, 10, 2000, 30, 40]
RN Reddy IT School – Core Python
False
Tuple:-
Is a collection of objects
It is represented with comma to separate values
It is an immutable object
An immitable object cannot be changed
In tuple insertion order is preserved
Every element on tuple can be accessed within index number
Nested tuple can also be created
A tuple is in another tuple is called nested tuple
Syntax of tuple:
< tuple.name>=(value1,value2,.........value n );
Example of tuple;
Empnames=(‘raju’,’rani’)
10 20 30 40 50 output
0 1 2 3 4
[10,20,30,40,50]
Step 2 :-
Empno=(10,20,30,40,50)
Print(empnos)
RN Reddy IT School – Core Python
step2:- output
(10, 20, 30, 40, 50)
Len():- it gives the number of elements in Tuple
Count():- this function returns the number of occurrence of a given elements in to tuple
Example:-
Step1 :- program
mylist=[10,20,30,40,50]
print(mylist.count(20))
step2:- output
3
Index():- this method will return the index value of a given element
Example:-
Step1 :- program
mylist=[10,20,30,40,50]
print(mylist.index(20))
step2:- output
1
RN Reddy IT School – Core Python
Min() or max():-
Example:-
Step1 :- program
mylist=[10,20,30,40,50]
print(„minimum value is : „,min(mylist))
print(„maximum value is : „,max(mylist))
step2:- output
maximum value is : 40
Eval() :- it will convert the given accepted value from string type to tuple
Example :-
print(mytuple)
output:-
(10,20,30,40,50)
List Tuple
list is immutable Tuple is immutable
list order is not fixed Tuple order is fixed
we can insert an element into list as we can insert an element in data file
a middle element as last element
RN Reddy IT School – Core Python
Set:-
Example:-
Step1:- program
myset=[10,20,30,40,50]
myset=set(myset)
print(myset)
step2:- output
Copy():- this method will copy the elements from one set to another set
Example:-
Step1:- program
myset=[10,20,30,40,50]
myset=myset.copy()
print(myset)
step2:- output
{50,20,40,10,30,}
Unions of set:-
Example:-
Step1:- program
set1={10,20,30,40,50}
set2={60,70,80,90,100}
set3=set1.union(set2)
print(set3)
step2:- output
{100, 70, 40, 10, 80, 50, 20, 90, 60, 30}
Insertion of set():- this method is used to take common elements from two sets
Example:-
Step1:- program
set1={10,20,30,40,50}
set2={10,70,40,90,100}
set3=set1.intersection(set2)
print(set3)
step2:- output
{40, 10}
Frozen set:-
Example:-
Step1:- program
mylist=[10,20,30,40,50]
myfrozenset=frozenset(mylist)
RN Reddy IT School – Core Python
print(myfrozenset)
print(type(myfrozenset))
step2:- output
<class 'frozenset'>
This method will convert the given list item to frozen set
Which method will convert any collection of to frozenset
Copy():- using this method we can copy the elements from one frozen set to another
frozenset
Example:-
Step1:- program
frozenset1=frozenset({1000,2000,3000,4000})
myfrozenset=frozenset1.copy()
print(myfrozenset)
step2:- output
Union():- this method will join the two frozenset values into store in 1 frozenset
Example:-
Step1:- program
frozenset1=frozenset({1000,2000,3000,4000})
frozenset2=frozenset({50,60,40,70,80})
myfrozenset=frozenset1.union(frozenset2)
print(myfrozenset)
step2:- output
Insertion():- this method will store the common values from two frozenset into third
frozenset
Example:-
Step1:- program
frozenset1=frozenset({50,2000,70,4000})
frozenset2=frozenset({50,60,40,70,80})
myfrozenset=frozenset1.intersection(frozenset2)
print(myfrozenset)
step2:- output
frozenset({50, 70})
Dictionary
Example
<emp_dict>={empname:raju}
Len():- this method will return the number of pairs with in the dictionaries
Example:-
Step1:- program
fruitsdict={111:'apple',222:'banana'}
print(fruitsdict.keys())
step2:- output
dict_keys([111, 222])
RN Reddy IT School – Core Python
Example:-
Step1:- program
fruitsdict={111:'apple',222:'banana'}
print(fruitsdict.values())
step2:- output
dict_values(['apple', 'banana'])
module
Python Operators
Operators are used to perform operations on variables and values.
Arithmetic operators
Assignment operators
Arithmetic Assignment operators
relational operators
Logical operators
Membership operators
Identity operators
Bitwise operators
Bitwise Assignment operators
Syntax:<variable>=<value>
Example : a=10
RN Reddy IT School – Core Python
Arithmetic operators:-
+ Addition x+y
- Subtraction x–y
* Multiplication x*y
/ Division x/y
% Modulus x%y
** Exponentiation x ** y
// Floor division x // y
RN Reddy IT School – Core Python
+= x += 3 x=x+3
-= x -= 3 x=x–3
*= x *= 3 x=x*3
/= x /= 3 x=x/3
%= x %= 3 x=x%3
//= x //= 3 x = x // 3
**= x **= 3 x = x ** 3
RN Reddy IT School – Core Python
Relational operators
Logical operators
And logical operator returns true when all given condition are true otherwise
returns false
OR logic operator
Or logical operator returns true if at least one condition is true within in given
Not(true)=false
Not(false)=true
RN Reddy IT School – Core Python
Membership operators
In
Notin
Example:-empnames=[‘raju’,’rajesh’,’suresh’]
‘raju’ in empnames
Output is = true
Identity operators
Is
Isnot
Example:-a=b=1000
A is b
o/p:- true
RN Reddy IT School – Core Python
Bitwise operators
OR Bitwise operators
|
Program
10&20--------(and)-------------------- o/p=0
10/20--------(or) ---------------------o/p=30
10^20--------(xor) --------------------o/p=30
10>>20-------(rightshift)------------ o/p=40
10<<20--------(leftshift)--------------o/p=40
a=10
B=20
A&=b ----meaning a=a&b
o/p = 0
a=10
B=20
A/=b ----meaning a=a/b
o/p = 30
a=10
B=20
A>>=b ----meaning a=a>>b
o/p = 2
a=10
B=20
A<<=b ----meaning a=a<<b
o/p = 40
RN Reddy IT School – Core Python
RN Reddy IT School
Online/Classroom Training’s