SlideShare a Scribd company logo
PYTHON- BASIC
INTRODUCTION TO PYTHON:
• Python is a general-purpose interpreted, interactive, object-oriented, and high-level programming
language.
• Python is a high-level, interpreted, interactive and object-oriented scripting language. Python is
designed to be highly readable.
 Python is Interpreted
 Python is Interactive
 Python is Object-Oriented
 Python is a Beginner's Language
ADVANTAGES OF PYTHON
As mentioned before, Python is one of the most widely used language over the web. I'm going to list
few of them here:
 Easy-to-learn
 Easy-to-read
 Easy-to-maintain
 A broad standard library
 Portable
APPLICATIONS OF PYTHON
CHARACTERISTICS OF PYTHON
Following are important characteristics of Python Programming −
 It supports functional and structured programming methods as well as OOP.
 It can be used as a scripting language or can be compiled to byte-code for
building large applications.
 It provides very high-level dynamic data types and supports dynamic type
checking.
 It supports automatic garbage collection.
 It can be easily integrated with C, C++, COM, ActiveX, CORBA, and Java.
EXAMPLES:
Program 1:
• Print(“"Hello, Python!")
Program 2:
# This program adds two numbers
num1 = 1.5
num2 = 6.3
# Add two numbers
sum = num1 + num2
# Display the sum
print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))
PYTHON DATA TYPES
• Variables can store data of different types, and different types can do different things.
Python has the following data types built-in by default, in these categories:
Text Type: str
Numeric
Types:
int, float, complex
Sequence
Types:
list, tuple, range
Mapping
Type:
dict
Set Types: set, frozenset
Boolean Type: bool
Binary Types: bytes, bytearray, memoryview
Getting the Data Type
x = 5
print(type(x))
Setting the Data Type
x = "Hello World"
#display x:
print(x)
#display the data type of x:
print(type(x))
NUMBERS
• Int :
Example:
x = 1
y =35656222554887711
z = -3255522
print(type(x))
print(type(y))
print(type(z))
• Float
Example:
x = 1.10
y = 1.0
z = -35.59
print(type(x))
print(type(y))
print(type(z))
• Complex
Example:
x = 3+5j
y = 5j
z = -5j
print(type(x))
print(type(y))
print(type(z))
STRINGS
Single Line:
a = "Hello"
print(a)
Multiline Strings:
a = """Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua."""
print(a)
• Slicing:
b = "Hello, World!"
print(b[2:5])
• Upper Case:
a = "Hello, World!"
print(a.upper())
• Lower Case:
a = "Hello, World!"
print(a.lower())
• String Concatenation:
a = "Hello"
b = "World"
c = a + b
print(c)
• String Replace:
a = "Hello"
a.replace(“H”,”K”)
• Remove Whitespace:
a = " Hello, World! "
print(a.strip())
PYTHON LISTS
• Lists are the most versatile of Python's compound data types. A list contains items separated by commas and
enclosed within square brackets ([]). To some extent, lists are similar to arrays in C. One difference between them
is that all the items belonging to a list can be of different data type.
• list = [ 'abcd', 786 , 2.23, 'john', 70.2 ]
• tinylist = [123, 'john']
• print list # Prints complete list
• print list[0] # Prints first element of the list
• print list[1:3] # Prints elements starting from 2nd till 3rd
• print list[2:] # Prints elements starting from 3rd element
• print tinylist * 2 # Prints list two times
• print list + tinylist # Prints concatenated lists
Add List Items:
Append Items:
thislist = ["apple", "banana", "cherry"]
thislist.append("orange")
print(thislist)
Insert Items:
thislist = ["apple", "banana", "cherry"]
thislist.insert(1, "orange")
print(thislist)
Extend List:
thislist = ["apple", "banana", "cherry"]
tropical = ["mango", "pineapple", "papaya"]
thislist.extend(tropical)
print(thislist)
Python - Remove List Items
Remove Specified Item:
thislist = ["apple", "banana", "cherry"]
thislist.remove("banana")
print(thislist)
Remove Specified Index:
thislist = ["apple", "banana", "cherry"]
thislist.pop(1)
print(thislist)
Del:
thislist = ["apple", "banana", "cherry"]
del thislist[0]
print(thislist)
Clear the List:
thislist = ["apple", "banana", "cherry"]
thislist.clear()
print(thislist)
Sort List Alphanumerically:
thislist = ["orange", "mango", "kiwi", "pineapple", "banana"]
thislist.sort()
print(thislist)
Sort Descending:
thislist = ["orange", "mango", "kiwi", "pineapple", "banana"]
thislist.sort(reverse = True)
print(thislist)
thislist = ["apple", "banana", "cherry"]
Copy a List:
mylist = thislist.copy()
print(mylist)
PYTHON TUPLES
• A tuple is another sequence data type that is similar to the list. A tuple consists of a number of values separated by commas. Unlike lists, however,
tuples are enclosed within parentheses.
• The main differences between lists and tuples are: Lists are enclosed in brackets ( [ ] ) and their elements and size can be changed, while tuples are
enclosed in parentheses ( ( ) ) and cannot be updated. Tuples can be thought of as read-only lists. For example
• tuple = ( 'abcd', 786 , 2.23, 'john', 70.2 )
• tinytuple = (123, 'john')
• print tuple # Prints the complete tuple
• print tuple[0] # Prints first element of the tuple
• print tuple[1:3] # Prints elements of the tuple starting from 2nd till 3rd
• print tuple[2:] # Prints elements of the tuple starting from 3rd element
• print tinytuple * 2 # Prints the contents of the tuple twice
• print tuple + tinytuple # Prints concatenated tuples
Access Tuple Items:
thistuple = ("apple", "banana", "cherry")
print(thistuple[1])
Negative Indexing:
thistuple = ("apple", "banana", "cherry")
print(thistuple[-1])
Change Tuple Values:
x = ("apple", "banana", "cherry")
x[1]=“Kiwi”
print(x)
Del:
thistuple = ("apple", "banana", "cherry")
del thistuple
print(thistuple)
PYTHON DICTIONARIES
• Python's dictionaries are kind of hash table type. They work like associative arrays or hashes found in Perl and consist of key-value pairs. A
dictionary key can be almost any Python type, but are usually numbers or strings. Values, on the other hand, can be any arbitrary Python object.
• Dictionaries are enclosed by curly braces ({ }) and values can be assigned and accessed using square braces ([]). For example −#!/usr/bin/python
• dict = {}
• dict['one'] = "This is one"
• dict[2] = "This is two"
• tinydict = {'name': 'john','code':6734, 'dept': 'sales’}
• print dict['one'] # Prints value for 'one' key
• print dict[2] # Prints value for 2 key
• print tinydict # Prints complete dictionary
• print tinydict.keys() # Prints all the keys
• print tinydict.values() # Prints all the values
Accessing Items:
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
x = thisdict["model"]
Change Values:
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
thisdict["year"] = 2018
Update Dictionary:
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
thisdict.update({"year": 2020})
Adding Items:
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
thisdict["color"] = "red"
print(thisdict)
Removing Items
• POP:
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
thisdict.pop("model")
print(thisdict)
• Del
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
del thisdict
print(thisdict) #this will cause an error because "thisdict" no longer exists.
• Clear
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
thisdict.clear()
print(thisdict)
DATA TYPE (SPECIAL ):
• Sets are used to store multiple items in a single variable.
• Set is one of 4 built-in data types in Python used to store collections of data, the other 3 are List, Tuple,
and Dictionary, all with different qualities and usage.
• A set is a collection which is both unordered and unindexed.
• Sets are written with curly brackets.
Create a Set:
• thisset = {"apple", "banana", "cherry"}
print(thisset)
Add Items:
thisset = {"apple", "banana", "cherry"}
thisset.add("orange")
print(thisset)
Remove Item:
thisset = {"apple", "banana", "cherry"}
thisset.remove("banana")
print(thisset)
Discard Item:
thisset = {"apple", "banana", "cherry"}
thisset.discard("banana")
print(thisset)
Clear:
thisset = {"apple", "banana", "cherry"}
thisset.clear()
print(thisset)
Del:
thisset = {"apple", "banana", "cherry"}
del thisset
print(thisset)
Pop:
thisset = {"apple", "banana", "cherry"}
x = thisset.pop()
print(x)
print(thisset)
Ad

More Related Content

Similar to Python- Basic. pptx with lists, tuples dictionaries and data types (20)

Core Concept_Python.pptx
Core Concept_Python.pptxCore Concept_Python.pptx
Core Concept_Python.pptx
Ashwini Raut
 
1691912901477_Python_Basics and list,tuple,string.pptx
1691912901477_Python_Basics and list,tuple,string.pptx1691912901477_Python_Basics and list,tuple,string.pptx
1691912901477_Python_Basics and list,tuple,string.pptx
KUSHSHARMA630049
 
Ry pyconjp2015 turtle
Ry pyconjp2015 turtleRy pyconjp2015 turtle
Ry pyconjp2015 turtle
Renyuan Lyu
 
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
sangeeta borde
 
Datatypes in Python.pdf
Datatypes in Python.pdfDatatypes in Python.pdf
Datatypes in Python.pdf
king931283
 
Python crush course
Python crush coursePython crush course
Python crush course
Mohammed El Rafie Tarabay
 
python.pdf
python.pdfpython.pdf
python.pdf
BurugollaRavi1
 
Python-Beginer-PartOnePython is one of the top programming languages in the w...
Python-Beginer-PartOnePython is one of the top programming languages in the w...Python-Beginer-PartOnePython is one of the top programming languages in the w...
Python-Beginer-PartOnePython is one of the top programming languages in the w...
ahmedosman389
 
Unit I - 1R introduction to R program.pptx
Unit I - 1R introduction to R program.pptxUnit I - 1R introduction to R program.pptx
Unit I - 1R introduction to R program.pptx
SreeLaya9
 
Python.pdf
Python.pdfPython.pdf
Python.pdf
Shivakumar B N
 
Python: The Dynamic!
Python: The Dynamic!Python: The Dynamic!
Python: The Dynamic!
Omid Mogharian
 
1-Object and Data Structures.pptx
1-Object and Data Structures.pptx1-Object and Data Structures.pptx
1-Object and Data Structures.pptx
RobNieves1
 
Python Programming
Python ProgrammingPython Programming
Python Programming
Saravanan T.M
 
Improve Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptxImprove Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptx
CatherineVania1
 
Keep it Stupidly Simple Introduce Python
Keep it Stupidly Simple Introduce PythonKeep it Stupidly Simple Introduce Python
Keep it Stupidly Simple Introduce Python
SushJalai
 
Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02
Fariz Darari
 
Basics of Python Programming
Basics of Python ProgrammingBasics of Python Programming
Basics of Python Programming
ManishJha237
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
baabtra.com - No. 1 supplier of quality freshers
 
Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.
supriyasarkar38
 
Python bible
Python biblePython bible
Python bible
adarsh j
 
Core Concept_Python.pptx
Core Concept_Python.pptxCore Concept_Python.pptx
Core Concept_Python.pptx
Ashwini Raut
 
1691912901477_Python_Basics and list,tuple,string.pptx
1691912901477_Python_Basics and list,tuple,string.pptx1691912901477_Python_Basics and list,tuple,string.pptx
1691912901477_Python_Basics and list,tuple,string.pptx
KUSHSHARMA630049
 
Ry pyconjp2015 turtle
Ry pyconjp2015 turtleRy pyconjp2015 turtle
Ry pyconjp2015 turtle
Renyuan Lyu
 
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
sangeeta borde
 
Datatypes in Python.pdf
Datatypes in Python.pdfDatatypes in Python.pdf
Datatypes in Python.pdf
king931283
 
Python-Beginer-PartOnePython is one of the top programming languages in the w...
Python-Beginer-PartOnePython is one of the top programming languages in the w...Python-Beginer-PartOnePython is one of the top programming languages in the w...
Python-Beginer-PartOnePython is one of the top programming languages in the w...
ahmedosman389
 
Unit I - 1R introduction to R program.pptx
Unit I - 1R introduction to R program.pptxUnit I - 1R introduction to R program.pptx
Unit I - 1R introduction to R program.pptx
SreeLaya9
 
1-Object and Data Structures.pptx
1-Object and Data Structures.pptx1-Object and Data Structures.pptx
1-Object and Data Structures.pptx
RobNieves1
 
Improve Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptxImprove Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptx
CatherineVania1
 
Keep it Stupidly Simple Introduce Python
Keep it Stupidly Simple Introduce PythonKeep it Stupidly Simple Introduce Python
Keep it Stupidly Simple Introduce Python
SushJalai
 
Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02
Fariz Darari
 
Basics of Python Programming
Basics of Python ProgrammingBasics of Python Programming
Basics of Python Programming
ManishJha237
 
Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.
supriyasarkar38
 
Python bible
Python biblePython bible
Python bible
adarsh j
 

Recently uploaded (20)

#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Web and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in RajpuraWeb and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in Rajpura
Erginous Technology
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Build 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHSBuild 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHS
TECH EHS Solution
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
TrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token ListingTrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token Listing
Trs Labs
 
Mastering Advance Window Functions in SQL.pdf
Mastering Advance Window Functions in SQL.pdfMastering Advance Window Functions in SQL.pdf
Mastering Advance Window Functions in SQL.pdf
Spiral Mantra
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Vaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without HallucinationsVaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without Hallucinations
john409870
 
Social Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTechSocial Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTech
Steve Jonas
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Web and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in RajpuraWeb and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in Rajpura
Erginous Technology
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Build 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHSBuild 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHS
TECH EHS Solution
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
TrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token ListingTrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token Listing
Trs Labs
 
Mastering Advance Window Functions in SQL.pdf
Mastering Advance Window Functions in SQL.pdfMastering Advance Window Functions in SQL.pdf
Mastering Advance Window Functions in SQL.pdf
Spiral Mantra
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Vaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without HallucinationsVaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without Hallucinations
john409870
 
Social Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTechSocial Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTech
Steve Jonas
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Ad

Python- Basic. pptx with lists, tuples dictionaries and data types

  • 2. INTRODUCTION TO PYTHON: • Python is a general-purpose interpreted, interactive, object-oriented, and high-level programming language. • Python is a high-level, interpreted, interactive and object-oriented scripting language. Python is designed to be highly readable.  Python is Interpreted  Python is Interactive  Python is Object-Oriented  Python is a Beginner's Language
  • 3. ADVANTAGES OF PYTHON As mentioned before, Python is one of the most widely used language over the web. I'm going to list few of them here:  Easy-to-learn  Easy-to-read  Easy-to-maintain  A broad standard library  Portable
  • 5. CHARACTERISTICS OF PYTHON Following are important characteristics of Python Programming −  It supports functional and structured programming methods as well as OOP.  It can be used as a scripting language or can be compiled to byte-code for building large applications.  It provides very high-level dynamic data types and supports dynamic type checking.  It supports automatic garbage collection.  It can be easily integrated with C, C++, COM, ActiveX, CORBA, and Java.
  • 6. EXAMPLES: Program 1: • Print(“"Hello, Python!") Program 2: # This program adds two numbers num1 = 1.5 num2 = 6.3 # Add two numbers sum = num1 + num2 # Display the sum print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))
  • 7. PYTHON DATA TYPES • Variables can store data of different types, and different types can do different things. Python has the following data types built-in by default, in these categories:
  • 8. Text Type: str Numeric Types: int, float, complex Sequence Types: list, tuple, range Mapping Type: dict Set Types: set, frozenset Boolean Type: bool Binary Types: bytes, bytearray, memoryview
  • 9. Getting the Data Type x = 5 print(type(x)) Setting the Data Type x = "Hello World" #display x: print(x) #display the data type of x: print(type(x))
  • 10. NUMBERS • Int : Example: x = 1 y =35656222554887711 z = -3255522 print(type(x)) print(type(y)) print(type(z)) • Float Example: x = 1.10 y = 1.0 z = -35.59 print(type(x)) print(type(y)) print(type(z)) • Complex Example: x = 3+5j y = 5j z = -5j print(type(x)) print(type(y)) print(type(z))
  • 11. STRINGS Single Line: a = "Hello" print(a) Multiline Strings: a = """Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.""" print(a)
  • 12. • Slicing: b = "Hello, World!" print(b[2:5]) • Upper Case: a = "Hello, World!" print(a.upper()) • Lower Case: a = "Hello, World!" print(a.lower())
  • 13. • String Concatenation: a = "Hello" b = "World" c = a + b print(c) • String Replace: a = "Hello" a.replace(“H”,”K”) • Remove Whitespace: a = " Hello, World! " print(a.strip())
  • 14. PYTHON LISTS • Lists are the most versatile of Python's compound data types. A list contains items separated by commas and enclosed within square brackets ([]). To some extent, lists are similar to arrays in C. One difference between them is that all the items belonging to a list can be of different data type. • list = [ 'abcd', 786 , 2.23, 'john', 70.2 ] • tinylist = [123, 'john'] • print list # Prints complete list • print list[0] # Prints first element of the list • print list[1:3] # Prints elements starting from 2nd till 3rd • print list[2:] # Prints elements starting from 3rd element • print tinylist * 2 # Prints list two times • print list + tinylist # Prints concatenated lists
  • 15. Add List Items: Append Items: thislist = ["apple", "banana", "cherry"] thislist.append("orange") print(thislist) Insert Items: thislist = ["apple", "banana", "cherry"] thislist.insert(1, "orange") print(thislist) Extend List: thislist = ["apple", "banana", "cherry"] tropical = ["mango", "pineapple", "papaya"] thislist.extend(tropical) print(thislist)
  • 16. Python - Remove List Items Remove Specified Item: thislist = ["apple", "banana", "cherry"] thislist.remove("banana") print(thislist) Remove Specified Index: thislist = ["apple", "banana", "cherry"] thislist.pop(1) print(thislist) Del: thislist = ["apple", "banana", "cherry"] del thislist[0] print(thislist) Clear the List: thislist = ["apple", "banana", "cherry"] thislist.clear() print(thislist)
  • 17. Sort List Alphanumerically: thislist = ["orange", "mango", "kiwi", "pineapple", "banana"] thislist.sort() print(thislist) Sort Descending: thislist = ["orange", "mango", "kiwi", "pineapple", "banana"] thislist.sort(reverse = True) print(thislist) thislist = ["apple", "banana", "cherry"] Copy a List: mylist = thislist.copy() print(mylist)
  • 18. PYTHON TUPLES • A tuple is another sequence data type that is similar to the list. A tuple consists of a number of values separated by commas. Unlike lists, however, tuples are enclosed within parentheses. • The main differences between lists and tuples are: Lists are enclosed in brackets ( [ ] ) and their elements and size can be changed, while tuples are enclosed in parentheses ( ( ) ) and cannot be updated. Tuples can be thought of as read-only lists. For example • tuple = ( 'abcd', 786 , 2.23, 'john', 70.2 ) • tinytuple = (123, 'john') • print tuple # Prints the complete tuple • print tuple[0] # Prints first element of the tuple • print tuple[1:3] # Prints elements of the tuple starting from 2nd till 3rd • print tuple[2:] # Prints elements of the tuple starting from 3rd element • print tinytuple * 2 # Prints the contents of the tuple twice • print tuple + tinytuple # Prints concatenated tuples
  • 19. Access Tuple Items: thistuple = ("apple", "banana", "cherry") print(thistuple[1]) Negative Indexing: thistuple = ("apple", "banana", "cherry") print(thistuple[-1]) Change Tuple Values: x = ("apple", "banana", "cherry") x[1]=“Kiwi” print(x) Del: thistuple = ("apple", "banana", "cherry") del thistuple print(thistuple)
  • 20. PYTHON DICTIONARIES • Python's dictionaries are kind of hash table type. They work like associative arrays or hashes found in Perl and consist of key-value pairs. A dictionary key can be almost any Python type, but are usually numbers or strings. Values, on the other hand, can be any arbitrary Python object. • Dictionaries are enclosed by curly braces ({ }) and values can be assigned and accessed using square braces ([]). For example −#!/usr/bin/python • dict = {} • dict['one'] = "This is one" • dict[2] = "This is two" • tinydict = {'name': 'john','code':6734, 'dept': 'sales’} • print dict['one'] # Prints value for 'one' key • print dict[2] # Prints value for 2 key • print tinydict # Prints complete dictionary • print tinydict.keys() # Prints all the keys • print tinydict.values() # Prints all the values
  • 21. Accessing Items: thisdict = { "brand": "Ford", "model": "Mustang", "year": 1964 } x = thisdict["model"] Change Values: thisdict = { "brand": "Ford", "model": "Mustang", "year": 1964 } thisdict["year"] = 2018
  • 22. Update Dictionary: thisdict = { "brand": "Ford", "model": "Mustang", "year": 1964 } thisdict.update({"year": 2020}) Adding Items: thisdict = { "brand": "Ford", "model": "Mustang", "year": 1964 } thisdict["color"] = "red" print(thisdict)
  • 23. Removing Items • POP: thisdict = { "brand": "Ford", "model": "Mustang", "year": 1964 } thisdict.pop("model") print(thisdict) • Del thisdict = { "brand": "Ford", "model": "Mustang", "year": 1964 } del thisdict print(thisdict) #this will cause an error because "thisdict" no longer exists. • Clear thisdict = { "brand": "Ford", "model": "Mustang", "year": 1964 } thisdict.clear() print(thisdict)
  • 24. DATA TYPE (SPECIAL ): • Sets are used to store multiple items in a single variable. • Set is one of 4 built-in data types in Python used to store collections of data, the other 3 are List, Tuple, and Dictionary, all with different qualities and usage. • A set is a collection which is both unordered and unindexed. • Sets are written with curly brackets. Create a Set: • thisset = {"apple", "banana", "cherry"} print(thisset)
  • 25. Add Items: thisset = {"apple", "banana", "cherry"} thisset.add("orange") print(thisset) Remove Item: thisset = {"apple", "banana", "cherry"} thisset.remove("banana") print(thisset) Discard Item: thisset = {"apple", "banana", "cherry"} thisset.discard("banana") print(thisset)
  • 26. Clear: thisset = {"apple", "banana", "cherry"} thisset.clear() print(thisset) Del: thisset = {"apple", "banana", "cherry"} del thisset print(thisset) Pop: thisset = {"apple", "banana", "cherry"} x = thisset.pop() print(x) print(thisset)