SlideShare uma empresa Scribd logo
1 de 38
Introduction To Python
Basics, sequences, Dictionaries, Sets
Python
– Python is an interepted language, which can save you considerable time
during program development because no compilation and linking is
necessary.
How to install Python
‱ Download latest version of python and install it on any drive: say
D:python
‱ Then follow the steps
–Got to Control Panel -> System -> Advanced system settings
–Click the Environment variables... button
–Edit PATH and append ;d:Python to the end
–Click OK.
–Open command prompt type python and enter
C Vs Python
Syntax comparison
Commenting
// comment single line
/* comment
multiple lines */
# comment single line
“ ” ” comment
multiple lines “ ” ”
C Python
Variables
//Declaring a variable
Int a=10;
Char c=‘a’;
Float f=1.12;
//Cannot assign multiple values
a=b=4 // Will result error
#No need of prior Declarations
a=10
c=‘a’
f=1.12
#Can assign multiple values simultaneously
x = y = z = 10
a, b, c = 1, 2, "john"
C Python
OutPut
printf(“Hello baabtra”);
Int a=10,b=25;
Printf(“%d %d”,a,b);
Printf(“value of a=%d and b= %d”,a,b)
print(“Hello baabtra”)
a=10
b=25
print(a,b)
print (“value of a=%d and b= %d” % (a,b))
C Python
InPut
int a;
Printf(“Enter the number”);
scanf(“%d”,&a);
a=input(“Enter the number”)
C Python
Arrays
int a[]={12,14,15,65,34};
printf(“%d”, a[3]);
No Arrays ! Instead Lists
a = [12,14,15,16,65,34,’baabtra’]
C Python
Arrays
int a[]={12,14,15,65,34};
printf(“%d”, a[3]);
No Arrays ! Instead Lists
a = [12,14,15,16,65,34,’baabtra’]
C Python
[ 12 , 14 , 15 , 16 , 65 , 34 , ’baabtra’ ]
0 1 2 3 4 5 6
-7 -6 -5 -4 -3 -2 -1
Lists in detail
‱ Print(a[2:5]) # prints 15,16,65
‱ Print(a[-6:-2]) # prints 14,15,16,65
‱ Print(a[4:]) # prints 65,34,baabtra
‱ Print(a[:2]) # prints 12,14,15
‱ a[2] = a[2] + 23; # Lists are mutable,we can change individual items
‱ a[0:2] = [1, 12] # We can replace a group of items together
‱ a[0:2] = [] # We can remove items together
‱ a[:] = [] # Clear the list
Lists in detail
‱ a.append(25) # adds an element at the end of list
‱ b =[55,66,77]
a.extend(b)
a=a+b;
‱ a.insert(1,99) # Inserts 99 at position 1
‱ a.pop(0) # pop elements at position 0
# Combines two lists
Strings
char a[]=“baabtra”; a= ‘baabtra’
b=“doesn’t”
C=“baabtra ”mentoring partner””
Strings are character lists, So can be used like any
other lists as we discussed earlier
print (a[0])
a.append(“m”);
C Python
Strings in detail
‱ String slicing
word=‘hello baabtra’
print(word[6:] # prints baabtra
word[: 6] # prints ‘hello ‘
word2= ‘good morning’ + word[6:]
Print(word2) # prints ‘good morning baabtra‘
Control structures
‱ Conditional Control Structures
‱ If
‱ If else
‱ Switch
‱ Loops
‱ For
‱ While
‱ Do while
Conditional Control Structures
‱ If
‱ If else
‱ Switch
Loops
‱ For
‱ While
‱Do while
C Python
If else
int a;
Printf(“Enter the number”);
scanf(“%d”,&a);
If(a>80)
Printf(“Distiction”);
else if(a>60)
Printf(“First class”);
else {
Printf(“Poor performancen”);
Printf(“Repeat the examn”); }
a=input(“Enter the number”)
if a>80 : print(“Distinction”)
elif a>60 : print(“First Class”)
else :
print(“Poor performance”)
print(“Repeat the exam”)
C Python
While Loop
int i=0;
whil(i<10)
{
printf(“%d”, i);
i=i+1;
}
i=0
while i<10:
print(i)
i=i+1
C Python
For Loop
int i=0;
for(i=0;i<10;i++)
{
printf(“%d”, i);
}
It’s quite a bit untraditional . We need to
define a range on which loop has to iterate.
This can be done using
Range(10,20) // creating a list with
elements from 10 to 20
For i in range(10) :
print(i) //print numbers up to 10
a=[12,14,16,’baabtra’]
For i in a :
print(i) //prints 12,14,16,baabtra
C Python
Other Control structure statements
‱ Break
Eg: If(a%2==0)
{
Print(“even”);
break;
}
‱ Break
The break statement is allowed only inside a loop
body. When break executes, the loop terminates.
Eg: for x in range(2, n):
if n % x == 0:
print n, 'equals', x, '*', n/x
break
C Python
Other Control structure statements
‱ Continue
for(i=1;i<20;i++)
{
if(i%2==1)
Continue;
Print(“%d is even”,i);
}
‱ Continue
The continue statement is allowed only inside a
loop body. When continue executes, the current
iteration of the loop body terminates, and
execution continues with the next iteration of the
loop
Eg:
For i in range(1,20)
If i%2==0:
continue
print(“%d is even” %(i))
C Python
Other Control structure statements
for(i=1;i<20;i++)
{
if(i%2==1)
{}
else
Print(“%d is even”,i);
}
‱ pass
The pass statement, which performs no action,
can be used when you have nothing specific to do.
Eg:
if a<10:
print(“less than 10”)
elif x>20:
pass # nothing to be done in this case
Else:
print(“in between 10 and 20”)
C Python
Functions
Int findSum(int a,int b)
{
int c;
c=a+b;
return c
}
d=findSum(10,15);
def findSum(a,b) :
return a+b
sum=findSum(112,321)
print(sum)
C Python
Task
‱ Write a simple python program which will have an array variable as below
‱ a= [50,15,12,4,2]
‱ Create 3 functions which will take the above array as argument and returns
the arithmetic output
–Add() //Outputs 83
–Substract() //Outputs 17
–Multiply() //Outputs 72000
That was the comparison !
So what’s new in python?
Sequences
Sequences
‱ A sequence is an ordered container of items, indexed by non-
negative integers. Python provides built-in sequence types ,they
are:-
– Strings (plain and Unicode), // We already have discussed
– Tuples
– Lists // We already have discussed
Tuples
Tuples
‱ A tuple is an immutable ordered sequence of items which may be of different
types.
– (100,200,300) # Tuple with three items
– (3.14,) # Tuple with one item
– ( ) # Empty tuple
‱ Immutable means we cant change the values of a tuple
‱ A tuple with exactly two items is also often called a pair.
Operation on Tuples
tpl_laptop = ('acer','lenova','hp','TOSHIBA')
tpl_numbers = (10,250,10,21,10)
tpl_numbers.count(10) # prints 3
tpl_laptop.index('hp') # prints 2
Task
‱ Create a python program that will accept two tuples as arguments
and return the difference between the tuple values,
Dictionaries
Dictionaries
‱ A dictionary is an arbitrary collection of objects indexed by nearly
arbitrary values called keys. They are mutable and, unlike
sequences, are unordered.
–Eg :{ 'x':42, 'y':3.14, 'z':7 }
–dict([[1,2],[3,4]]) # similar to {1:2,3:4}
Operation on Dictionaries
‱ dic={'a':1,'b':2,'c':3}
– len(dic) # returns 3
– del dic['a'] # removes element with key ‘a’
– a in dic # returns ‘True’ .Bur
– dic.items() #Displays elements
– for i in dic.iterkeys():
... print i # Returns key
– for i in dic. itervalues():
... print i # Return values
Task
‱ Write a python program with a dictionary variable with key as
English word and value as meaning of the word.
‱ User should be able to give an input value which must be checked
whether exist inside the dictionary or not and if it is there print
the meaning of that word
Sets
Sets
‱ Sets are unordered collections of unique (non duplicate) elements.
– St= set(‘baabtra calicut’)
– print (st) #prints {‘r’,’u’,’t’,’c’,’b’,’a’,’i’,’l’}
Operation on sets
‱ st1=set(‘baabtracalicut’)
‱ st2=set(‘baabtra’)
– st1.issubset(st2) #Returns true
– st2.issuperset(st1) #Returns true
– st1. remove(‘mentoringpartner')
– st1. remove(‘calicut)
Questions?
“A good question deserve a good grade
”

Mais conteĂșdo relacionado

Mais procurados

The best of AltJava is Xtend
The best of AltJava is XtendThe best of AltJava is Xtend
The best of AltJava is Xtendtakezoe
 
Python programming Part -6
Python programming Part -6Python programming Part -6
Python programming Part -6Megha V
 
Dictionary
DictionaryDictionary
DictionaryPooja B S
 
The Ring programming language version 1.2 book - Part 11 of 84
The Ring programming language version 1.2 book - Part 11 of 84The Ring programming language version 1.2 book - Part 11 of 84
The Ring programming language version 1.2 book - Part 11 of 84Mahmoud Samir Fayed
 
Functions in python
Functions in pythonFunctions in python
Functions in pythonIlian Iliev
 
Algorithm analysis and design
Algorithm analysis and designAlgorithm analysis and design
Algorithm analysis and designMegha V
 
Python- Regular expression
Python- Regular expressionPython- Regular expression
Python- Regular expressionMegha V
 
Type header file in c++ and its function
Type header file in c++ and its functionType header file in c++ and its function
Type header file in c++ and its functionFrankie Jones
 
Python ppt
Python pptPython ppt
Python pptAnush verma
 
The Ring programming language version 1.3 book - Part 13 of 88
The Ring programming language version 1.3 book - Part 13 of 88The Ring programming language version 1.3 book - Part 13 of 88
The Ring programming language version 1.3 book - Part 13 of 88Mahmoud Samir Fayed
 
2.2 higher order-functions
2.2 higher order-functions2.2 higher order-functions
2.2 higher order-functionsfuturespective
 
Java Foundations: Lists, ArrayList<T>
Java Foundations: Lists, ArrayList<T>Java Foundations: Lists, ArrayList<T>
Java Foundations: Lists, ArrayList<T>Svetlin Nakov
 

Mais procurados (20)

The best of AltJava is Xtend
The best of AltJava is XtendThe best of AltJava is Xtend
The best of AltJava is Xtend
 
Python programming : Strings
Python programming : StringsPython programming : Strings
Python programming : Strings
 
Python programming Part -6
Python programming Part -6Python programming Part -6
Python programming Part -6
 
Dictionary
DictionaryDictionary
Dictionary
 
The Ring programming language version 1.2 book - Part 11 of 84
The Ring programming language version 1.2 book - Part 11 of 84The Ring programming language version 1.2 book - Part 11 of 84
The Ring programming language version 1.2 book - Part 11 of 84
 
Functions in python
Functions in pythonFunctions in python
Functions in python
 
Algorithm analysis and design
Algorithm analysis and designAlgorithm analysis and design
Algorithm analysis and design
 
Python- Regular expression
Python- Regular expressionPython- Regular expression
Python- Regular expression
 
Type header file in c++ and its function
Type header file in c++ and its functionType header file in c++ and its function
Type header file in c++ and its function
 
Python numbers
Python numbersPython numbers
Python numbers
 
Arrays
ArraysArrays
Arrays
 
Python ppt
Python pptPython ppt
Python ppt
 
Python basics
Python basicsPython basics
Python basics
 
The Ring programming language version 1.3 book - Part 13 of 88
The Ring programming language version 1.3 book - Part 13 of 88The Ring programming language version 1.3 book - Part 13 of 88
The Ring programming language version 1.3 book - Part 13 of 88
 
2.2 higher order-functions
2.2 higher order-functions2.2 higher order-functions
2.2 higher order-functions
 
Python
PythonPython
Python
 
Strings in python
Strings in pythonStrings in python
Strings in python
 
Java Foundations: Lists, ArrayList<T>
Java Foundations: Lists, ArrayList<T>Java Foundations: Lists, ArrayList<T>
Java Foundations: Lists, ArrayList<T>
 
Python : Regular expressions
Python : Regular expressionsPython : Regular expressions
Python : Regular expressions
 
python codes
python codespython codes
python codes
 

Semelhante a Introduction to python

Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayUtkarsh Sengar
 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxAbhishek Tirkey
 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxGauravPandey43518
 
Chapter 2 Python Language Basics, IPython.pptx
Chapter 2 Python Language Basics, IPython.pptxChapter 2 Python Language Basics, IPython.pptx
Chapter 2 Python Language Basics, IPython.pptxSovannDoeur
 
Python language data types
Python language data typesPython language data types
Python language data typesHarry Potter
 
Python language data types
Python language data typesPython language data types
Python language data typesHoang Nguyen
 
Python language data types
Python language data typesPython language data types
Python language data typesLuis Goldster
 
Python language data types
Python language data typesPython language data types
Python language data typesTony Nguyen
 
Python language data types
Python language data typesPython language data types
Python language data typesFraboni Ec
 
Python language data types
Python language data typesPython language data types
Python language data typesJames Wong
 
Python language data types
Python language data typesPython language data types
Python language data typesYoung Alista
 
Python in 90mins
Python in 90minsPython in 90mins
Python in 90minsLarry Cai
 
Python basics
Python basicsPython basics
Python basicsHoang Nguyen
 
Python basics
Python basicsPython basics
Python basicsTony Nguyen
 

Semelhante a Introduction to python (20)

C++ process new
C++ process newC++ process new
C++ process new
 
Python Basics
Python BasicsPython Basics
Python Basics
 
Functions
FunctionsFunctions
Functions
 
Python
PythonPython
Python
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptx
 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptx
 
Chapter 2 Python Language Basics, IPython.pptx
Chapter 2 Python Language Basics, IPython.pptxChapter 2 Python Language Basics, IPython.pptx
Chapter 2 Python Language Basics, IPython.pptx
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python in 90mins
Python in 90minsPython in 90mins
Python in 90mins
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 

Mais de baabtra.com - No. 1 supplier of quality freshers

Mais de baabtra.com - No. 1 supplier of quality freshers (20)

Agile methodology and scrum development
Agile methodology and scrum developmentAgile methodology and scrum development
Agile methodology and scrum development
 
Best coding practices
Best coding practicesBest coding practices
Best coding practices
 
Core java - baabtra
Core java - baabtraCore java - baabtra
Core java - baabtra
 
Acquiring new skills what you should know
Acquiring new skills   what you should knowAcquiring new skills   what you should know
Acquiring new skills what you should know
 
Baabtra.com programming at school
Baabtra.com programming at schoolBaabtra.com programming at school
Baabtra.com programming at school
 
99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love 99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
 
Chapter 5 transactions and dcl statements
Chapter 5  transactions and dcl statementsChapter 5  transactions and dcl statements
Chapter 5 transactions and dcl statements
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Microsoft holo lens
Microsoft holo lensMicrosoft holo lens
Microsoft holo lens
 
Blue brain
Blue brainBlue brain
Blue brain
 
5g
5g5g
5g
 
Aptitude skills baabtra
Aptitude skills baabtraAptitude skills baabtra
Aptitude skills baabtra
 
Gd baabtra
Gd baabtraGd baabtra
Gd baabtra
 

Último

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...gurkirankumar98700
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel AraĂșjo
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 

Último (20)

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 

Introduction to python

  • 1. Introduction To Python Basics, sequences, Dictionaries, Sets
  • 2. Python – Python is an interepted language, which can save you considerable time during program development because no compilation and linking is necessary.
  • 3. How to install Python ‱ Download latest version of python and install it on any drive: say D:python ‱ Then follow the steps –Got to Control Panel -> System -> Advanced system settings –Click the Environment variables... button –Edit PATH and append ;d:Python to the end –Click OK. –Open command prompt type python and enter
  • 4. C Vs Python Syntax comparison
  • 5. Commenting // comment single line /* comment multiple lines */ # comment single line “ ” ” comment multiple lines “ ” ” C Python
  • 6. Variables //Declaring a variable Int a=10; Char c=‘a’; Float f=1.12; //Cannot assign multiple values a=b=4 // Will result error #No need of prior Declarations a=10 c=‘a’ f=1.12 #Can assign multiple values simultaneously x = y = z = 10 a, b, c = 1, 2, "john" C Python
  • 7. OutPut printf(“Hello baabtra”); Int a=10,b=25; Printf(“%d %d”,a,b); Printf(“value of a=%d and b= %d”,a,b) print(“Hello baabtra”) a=10 b=25 print(a,b) print (“value of a=%d and b= %d” % (a,b)) C Python
  • 8. InPut int a; Printf(“Enter the number”); scanf(“%d”,&a); a=input(“Enter the number”) C Python
  • 9. Arrays int a[]={12,14,15,65,34}; printf(“%d”, a[3]); No Arrays ! Instead Lists a = [12,14,15,16,65,34,’baabtra’] C Python
  • 10. Arrays int a[]={12,14,15,65,34}; printf(“%d”, a[3]); No Arrays ! Instead Lists a = [12,14,15,16,65,34,’baabtra’] C Python [ 12 , 14 , 15 , 16 , 65 , 34 , ’baabtra’ ] 0 1 2 3 4 5 6 -7 -6 -5 -4 -3 -2 -1
  • 11. Lists in detail ‱ Print(a[2:5]) # prints 15,16,65 ‱ Print(a[-6:-2]) # prints 14,15,16,65 ‱ Print(a[4:]) # prints 65,34,baabtra ‱ Print(a[:2]) # prints 12,14,15 ‱ a[2] = a[2] + 23; # Lists are mutable,we can change individual items ‱ a[0:2] = [1, 12] # We can replace a group of items together ‱ a[0:2] = [] # We can remove items together ‱ a[:] = [] # Clear the list
  • 12. Lists in detail ‱ a.append(25) # adds an element at the end of list ‱ b =[55,66,77] a.extend(b) a=a+b; ‱ a.insert(1,99) # Inserts 99 at position 1 ‱ a.pop(0) # pop elements at position 0 # Combines two lists
  • 13. Strings char a[]=“baabtra”; a= ‘baabtra’ b=“doesn’t” C=“baabtra ”mentoring partner”” Strings are character lists, So can be used like any other lists as we discussed earlier print (a[0]) a.append(“m”); C Python
  • 14. Strings in detail ‱ String slicing word=‘hello baabtra’ print(word[6:] # prints baabtra word[: 6] # prints ‘hello ‘ word2= ‘good morning’ + word[6:] Print(word2) # prints ‘good morning baabtra‘
  • 15. Control structures ‱ Conditional Control Structures ‱ If ‱ If else ‱ Switch ‱ Loops ‱ For ‱ While ‱ Do while Conditional Control Structures ‱ If ‱ If else ‱ Switch Loops ‱ For ‱ While ‱Do while C Python
  • 16. If else int a; Printf(“Enter the number”); scanf(“%d”,&a); If(a>80) Printf(“Distiction”); else if(a>60) Printf(“First class”); else { Printf(“Poor performancen”); Printf(“Repeat the examn”); } a=input(“Enter the number”) if a>80 : print(“Distinction”) elif a>60 : print(“First Class”) else : print(“Poor performance”) print(“Repeat the exam”) C Python
  • 17. While Loop int i=0; whil(i<10) { printf(“%d”, i); i=i+1; } i=0 while i<10: print(i) i=i+1 C Python
  • 18. For Loop int i=0; for(i=0;i<10;i++) { printf(“%d”, i); } It’s quite a bit untraditional . We need to define a range on which loop has to iterate. This can be done using Range(10,20) // creating a list with elements from 10 to 20 For i in range(10) : print(i) //print numbers up to 10 a=[12,14,16,’baabtra’] For i in a : print(i) //prints 12,14,16,baabtra C Python
  • 19. Other Control structure statements ‱ Break Eg: If(a%2==0) { Print(“even”); break; } ‱ Break The break statement is allowed only inside a loop body. When break executes, the loop terminates. Eg: for x in range(2, n): if n % x == 0: print n, 'equals', x, '*', n/x break C Python
  • 20. Other Control structure statements ‱ Continue for(i=1;i<20;i++) { if(i%2==1) Continue; Print(“%d is even”,i); } ‱ Continue The continue statement is allowed only inside a loop body. When continue executes, the current iteration of the loop body terminates, and execution continues with the next iteration of the loop Eg: For i in range(1,20) If i%2==0: continue print(“%d is even” %(i)) C Python
  • 21. Other Control structure statements for(i=1;i<20;i++) { if(i%2==1) {} else Print(“%d is even”,i); } ‱ pass The pass statement, which performs no action, can be used when you have nothing specific to do. Eg: if a<10: print(“less than 10”) elif x>20: pass # nothing to be done in this case Else: print(“in between 10 and 20”) C Python
  • 22. Functions Int findSum(int a,int b) { int c; c=a+b; return c } d=findSum(10,15); def findSum(a,b) : return a+b sum=findSum(112,321) print(sum) C Python
  • 23. Task ‱ Write a simple python program which will have an array variable as below ‱ a= [50,15,12,4,2] ‱ Create 3 functions which will take the above array as argument and returns the arithmetic output –Add() //Outputs 83 –Substract() //Outputs 17 –Multiply() //Outputs 72000
  • 24. That was the comparison ! So what’s new in python?
  • 26. Sequences ‱ A sequence is an ordered container of items, indexed by non- negative integers. Python provides built-in sequence types ,they are:- – Strings (plain and Unicode), // We already have discussed – Tuples – Lists // We already have discussed
  • 28. Tuples ‱ A tuple is an immutable ordered sequence of items which may be of different types. – (100,200,300) # Tuple with three items – (3.14,) # Tuple with one item – ( ) # Empty tuple ‱ Immutable means we cant change the values of a tuple ‱ A tuple with exactly two items is also often called a pair.
  • 29. Operation on Tuples tpl_laptop = ('acer','lenova','hp','TOSHIBA') tpl_numbers = (10,250,10,21,10) tpl_numbers.count(10) # prints 3 tpl_laptop.index('hp') # prints 2
  • 30. Task ‱ Create a python program that will accept two tuples as arguments and return the difference between the tuple values,
  • 32. Dictionaries ‱ A dictionary is an arbitrary collection of objects indexed by nearly arbitrary values called keys. They are mutable and, unlike sequences, are unordered. –Eg :{ 'x':42, 'y':3.14, 'z':7 } –dict([[1,2],[3,4]]) # similar to {1:2,3:4}
  • 33. Operation on Dictionaries ‱ dic={'a':1,'b':2,'c':3} – len(dic) # returns 3 – del dic['a'] # removes element with key ‘a’ – a in dic # returns ‘True’ .Bur – dic.items() #Displays elements – for i in dic.iterkeys(): ... print i # Returns key – for i in dic. itervalues(): ... print i # Return values
  • 34. Task ‱ Write a python program with a dictionary variable with key as English word and value as meaning of the word. ‱ User should be able to give an input value which must be checked whether exist inside the dictionary or not and if it is there print the meaning of that word
  • 35. Sets
  • 36. Sets ‱ Sets are unordered collections of unique (non duplicate) elements. – St= set(‘baabtra calicut’) – print (st) #prints {‘r’,’u’,’t’,’c’,’b’,’a’,’i’,’l’}
  • 37. Operation on sets ‱ st1=set(‘baabtracalicut’) ‱ st2=set(‘baabtra’) – st1.issubset(st2) #Returns true – st2.issuperset(st1) #Returns true – st1. remove(‘mentoringpartner') – st1. remove(‘calicut)
  • 38. Questions? “A good question deserve a good grade
”