SlideShare uma empresa Scribd logo
1 de 38
INTRODUCTION TO PYTHON
SUBMITTED BY: NIMRAH AFZAL
Introduction to Python
• Python is an interpreted, object-oriented, high-level programming
language
• Python's simple, easy to learn syntax emphasizes readability and
therefore reduces the cost of program maintenance.
• A standard distribution includes many modules
• Dynamic typed Source can be compiled or run just-in-time Similar to
perl, tcl, ruby
Why Python
• Python works on different platforms (Windows, Mac, Linux,
Raspberry Pi, etc).
• Python has a simple syntax similar to the English language.
• Python has syntax that allows developers to write programs with
fewer lines than some other programming languages.
• Python runs on an interpreter system, meaning that code can be
executed as soon as it is written. This means that prototyping can be
very quick.
• Python can be treated in a procedural way, an object-oriented way or
a functional way
Python Interfaces
IDLE : a cross-platform Python development
Python Win: a Windows only interface to Python
• Python Shell running 'python' from the Command Line opens this
interactive shell
IDLE — Development Environment
• IDLE helps you program in Python by
• color-coding your program code
• debugging ' auto-indent ‘
• interactive shell Python Shell
• Auto indent
Example python
Print (“Hello World”)
output:
Hello World
Python Indentation
• Indentation refers to the spaces at the beginning of a code line.
• Where in other programming languages the indentation in code is for
readability only, the indentation in Python is very important.
• Python uses indentation to indicate a block of code.
Example:
if 5 > 2:
print("Five is greater than two!")
Python Comments
• Comments can be used to explain Python code.
• Comments can be used to make the code more readable.
• Comments can be used to prevent execution when testing code
Example
#This is a comment
print("Hello, World!")
Python Variables
• Variables are containers for storing data values
• Python has no command for declaring a variable.
• A variable is created the moment you first assign a value to it
Example
x = 5
y = "John"
print(x)
print(y)
Python - Variable Names
A variable can have a short name (like x and y) or a more descriptive
name (age, carname, total_volume). Rules for Python variables:
• A variable name must start with a letter or the underscore character
• A variable name cannot start with a number
• A variable name can only contain alpha-numeric characters and
underscores (A-z, 0-9, and _ )
• Variable names are case-sensitive (age, Age and AGE are three
different variables)
Example
• Legal variable names:
myvar = "John"
my_var = "John"
_my_var = "John"
myVar = "John"
MYVAR = "John"
myvar2 = "John"
Python Variables - Assign Multiple Values
Python allows you to assign values to multiple variables in one line:
Example
x, y, z = "Orange", "Banana", "Cherry"
print(x)
print(y)
print(z)
Python - Output Variables
Python output variable function are print()
Example
x = "Python is awesome"
print(x)
Python - Global Variables
• Variables that are created outside of a function (as in all of the examples above)
are known as global variables.
• Global variables can be used by everyone, both inside of functions and outside
Example
x = "awesome"
def myfunc():
x = "fantastic"
print("Python is " + x)
myfunc()
print("Python is " + x)
Python Data Types
• In programming, data type is an important concept.
• 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
Python Numbers
• There are three Numeric types in python
• Int
• Float
• Complex
Example
x = 1 # int
y = 2.8 # float
z = 1j # complex
Python Casting
There may be times when you want to specify a type on to a variable. This
can be done with casting. Python is an object-orientated language, and as
such it uses classes to define data types, including its primitive types.
Casting in python is therefore done using constructor functions:
• int() - constructs an integer number from an integer literal, a float literal
(by removing all decimals), or a string literal (providing the string
represents a whole number)
• float() - constructs a float number from an integer literal, a float literal or a
string literal (providing the string represents a float or an integer)
• str() - constructs a string from a wide variety of data types, including
strings, integer literals and float literals
Example
Integers:
x = int(1) # x will be 1
y = int(2.8) # y will be 2
Floats:
x = float(1) # x will be 1.0
y = float(2.8) # y will be 2.8
Strings:
x = str("s1") # x will be 's1'
y = str(2) # y will be '2
Python Strings
• Strings in python are surrounded by either single quotation marks, or
double quotation marks.
• 'hello' is the same as "hello“
Assign String to a Variable
Assigning a string to a variable is done with the variable name followed
by an equal sign and the string:
Example
a = "Hello"
print(a)
Python - Slicing Strings
• You can return a range of characters by using the slice syntax.
• Specify the start index and the end index, separated by a colon, to
return a part of the string.
Example
Get the characters from position 2 to position 5 (not included):
b = "Hello, World!"
print(b[2:5])
Output
llo
Python - Modify Strings
Python has a set of built-in methods that you can use on strings.
Upper Case
Example
a = "Hello, World!"
print(a.upper())
Output
HELLO, WORLD!
Lower Case
a = "Hello, World!"
print(a.lower())
OUTPUT
Hello,world!
Python - String Concatenation
To concatenate, or combine, two strings you can use the + operator.
a = "Hello"
b = "World"
c = a + b
print(c)
Python - Format – Strings
age = 36
txt = "My name is John, and I am {}"
print(txt.format(age))
Output
My name is John, and I am 36
Python Booleans
Boolean represent true or false
Example
print(10 > 9)
print(10 == 9)
print(10 < 9)
Output
True
False
False
Python Operators
• Operators are used to perform operations on variables and values.
Example
print(10 + 5)
Output
15
Python Lists
Lists are used to store multiple items in a single variable
thislist = ["apple", "banana", "cherry"]
print(thislist)
Python - Access List Items
List items are indexed and you can access them by referring to the
index number:
Example
Print the second item of the list:
thislist = ["apple", "banana", "cherry"]
print(thislist[1])
Python - Change List Items:
To change the value of a specific item, refer to the index number:
thislist = ["apple", "banana", "cherry"]
thislist[1] = "blackcurrant"
print(thislist)
Python - Add List Items
• To add an item to the end of the list, use the append() method
thislist = ["apple", "banana", "cherry"]
thislist.append("orange")
print(thislist)
Output
['apple', 'banana', 'cherry', 'orange']
Python - Loop Lists
• You can loop through the list by using for loop
Example
Print all items in the list, one by one:
thislist = ["apple", "banana", "cherry"]
for x in thislist:
print(x)
Output
apple
banana
cherry
Using a While Loop
thislist = ["apple", "banana", "cherry"]
i = 0
while i < len(thislist):
print(thislist[i])
i = i + 1
Output
apple
banana
cherry
Python Tuples
thistuple = ("apple", "banana", "cherry")
print(thistuple)
Python - Access Tuple Items
You can access tuple items by referring to the index number, inside
square brackets:
Example
Print the second item in the tuple:
thistuple = ("apple", "banana", "cherry")
print(thistuple[1])
Python - Update Tuples
• Once a tuple is created, you cannot change its values. Tuples
are unchangeable, or immutable as it also is called.
• But there is a workaround. You can convert the tuple into a list, change the
list, and convert the list back into a tuple.
Example
Convert the tuple into a list to be able to change it:
x = ("apple", "banana", "cherry")
y = list(x)
y[1] = "kiwi"
x = tuple(y)
print(x)
Python Dictionaries
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
Print(thisdict)
Output
{'brand': 'Ford', 'model': 'Mustang', 'year': 1964}
Python Functions
• A function is a block of code which only runs when it is called.
• You can pass data, known as parameters, into a function.
• A function can return data as a result
Example
def my_function():
print("Hello from a function")
Output
Hello from a function
Python Lambda
• A lambda function is a small anonymous function.
• A lambda function can take any number of arguments, but can only
have one expression.
Example
x = lambda a : a + 10
print(x(5))
Output
15
Python Arrays
• Arrays are used to store multiple values in one single variable:
Example
cars = ["Ford", "Volvo", "BMW"]
Print(cars)
Output
['Ford', 'Volvo', 'BMW']
Python Classes and Objects
• Python is an object oriented programming language.
• Almost everything in Python is an object, with its properties and methods.
• A Class is like an object constructor, or a "blueprint" for creating objects
Example
class MyClass:
x = 5
p1 = MyClass()
print(p1.x)
Output
5
The __init__() Function
All classes have a function called __init__(), which is always executed when
the class is being initiated.
Example
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
p1 = Person("John", 36)
print(p1.name)
print(p1.age)
Output
John
36
Python Inheritance
• Inheritance allows us to define a class that inherits all the methods and properties from another
class.
Parent class is the class being inherited from, also called base class.
Child class is the class that inherits from another class, also called derived class.
class Person:
def __init__(self, fname, lname):
self.firstname = fname
self.lastname = lname
def printname(self):
print(self.firstname, self.lastname)
#Use the Person class to create an object, and then execute the printname method:
x = Person("John", "Doe")
x.printname()
Output
John Doe
Python Math
Python has a set of built-in math functions, including an extensive math
module, that allows you to perform mathematical tasks on numbers.
Example min,max:
x = min(5, 10, 25)
y = max(5, 10, 25)
print(x)
print(y)

Mais conteúdo relacionado

Mais procurados

Full Python in 20 slides
Full Python in 20 slidesFull Python in 20 slides
Full Python in 20 slidesrfojdar
 
Phython Programming Language
Phython Programming LanguagePhython Programming Language
Phython Programming LanguageR.h. Himel
 
Introduction to-python
Introduction to-pythonIntroduction to-python
Introduction to-pythonAakashdata
 
GDG Helwan Introduction to python
GDG Helwan Introduction to pythonGDG Helwan Introduction to python
GDG Helwan Introduction to pythonMohamed Hegazy
 
Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Paige Bailey
 
Presentation on python
Presentation on pythonPresentation on python
Presentation on pythonwilliam john
 
Python Programming Language
Python Programming LanguagePython Programming Language
Python Programming LanguageDr.YNM
 
Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Pedro Rodrigues
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programmingSrinivas Narasegouda
 
Python Course | Python Programming | Python Tutorial | Python Training | Edureka
Python Course | Python Programming | Python Tutorial | Python Training | EdurekaPython Course | Python Programming | Python Tutorial | Python Training | Edureka
Python Course | Python Programming | Python Tutorial | Python Training | EdurekaEdureka!
 

Mais procurados (20)

Full Python in 20 slides
Full Python in 20 slidesFull Python in 20 slides
Full Python in 20 slides
 
Phython Programming Language
Phython Programming LanguagePhython Programming Language
Phython Programming Language
 
Introduction to-python
Introduction to-pythonIntroduction to-python
Introduction to-python
 
GDG Helwan Introduction to python
GDG Helwan Introduction to pythonGDG Helwan Introduction to python
GDG Helwan Introduction to python
 
Introduction to Python Basics Programming
Introduction to Python Basics ProgrammingIntroduction to Python Basics Programming
Introduction to Python Basics Programming
 
Python
PythonPython
Python
 
Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)
 
Presentation on python
Presentation on pythonPresentation on python
Presentation on python
 
Python Programming Language
Python Programming LanguagePython Programming Language
Python Programming Language
 
Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)
 
Python final ppt
Python final pptPython final ppt
Python final ppt
 
Python programming
Python  programmingPython  programming
Python programming
 
Python Tutorial Part 1
Python Tutorial Part 1Python Tutorial Part 1
Python Tutorial Part 1
 
Beginning Python Programming
Beginning Python ProgrammingBeginning Python Programming
Beginning Python Programming
 
Python
PythonPython
Python
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Python basic
Python basicPython basic
Python basic
 
Python
PythonPython
Python
 
Python Course | Python Programming | Python Tutorial | Python Training | Edureka
Python Course | Python Programming | Python Tutorial | Python Training | EdurekaPython Course | Python Programming | Python Tutorial | Python Training | Edureka
Python Course | Python Programming | Python Tutorial | Python Training | Edureka
 

Semelhante a INTRODUCTION TO PYTHON.pptx

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
 
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.pptxsangeeta borde
 
Python (3).pdf
Python (3).pdfPython (3).pdf
Python (3).pdfsamiwaris2
 
modul-python-part1.pptx
modul-python-part1.pptxmodul-python-part1.pptx
modul-python-part1.pptxYusuf Ayuba
 
Python basics_ part1
Python basics_ part1Python basics_ part1
Python basics_ part1Elaf A.Saeed
 
1. python programming
1. python programming1. python programming
1. python programmingsreeLekha51
 
Python (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualizePython (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualizeIruolagbePius
 
Python Basics by Akanksha Bali
Python Basics by Akanksha BaliPython Basics by Akanksha Bali
Python Basics by Akanksha BaliAkanksha Bali
 
pysdasdasdsadsadsadsadsadsadasdasdthon1.ppt
pysdasdasdsadsadsadsadsadsadasdasdthon1.pptpysdasdasdsadsadsadsadsadsadasdasdthon1.ppt
pysdasdasdsadsadsadsadsadsadasdasdthon1.pptkashifmajeedjanjua
 
Introductio_to_python_progamming_ppt.ppt
Introductio_to_python_progamming_ppt.pptIntroductio_to_python_progamming_ppt.ppt
Introductio_to_python_progamming_ppt.pptHiralPatel798996
 

Semelhante a INTRODUCTION TO PYTHON.pptx (20)

Python Programming
Python ProgrammingPython Programming
Python Programming
 
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.
 
python_class.pptx
python_class.pptxpython_class.pptx
python_class.pptx
 
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
 
Python (3).pdf
Python (3).pdfPython (3).pdf
Python (3).pdf
 
modul-python-part1.pptx
modul-python-part1.pptxmodul-python-part1.pptx
modul-python-part1.pptx
 
Python basics_ part1
Python basics_ part1Python basics_ part1
Python basics_ part1
 
1. python programming
1. python programming1. python programming
1. python programming
 
Python (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualizePython (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualize
 
Unit -1 CAP.pptx
Unit -1 CAP.pptxUnit -1 CAP.pptx
Unit -1 CAP.pptx
 
Python Basics by Akanksha Bali
Python Basics by Akanksha BaliPython Basics by Akanksha Bali
Python Basics by Akanksha Bali
 
python1.ppt
python1.pptpython1.ppt
python1.ppt
 
python1.ppt
python1.pptpython1.ppt
python1.ppt
 
Python Basics
Python BasicsPython Basics
Python Basics
 
python1.ppt
python1.pptpython1.ppt
python1.ppt
 
Lenguaje Python
Lenguaje PythonLenguaje Python
Lenguaje Python
 
pysdasdasdsadsadsadsadsadsadasdasdthon1.ppt
pysdasdasdsadsadsadsadsadsadasdasdthon1.pptpysdasdasdsadsadsadsadsadsadasdasdthon1.ppt
pysdasdasdsadsadsadsadsadsadasdasdthon1.ppt
 
coolstuff.ppt
coolstuff.pptcoolstuff.ppt
coolstuff.ppt
 
python1.ppt
python1.pptpython1.ppt
python1.ppt
 
Introductio_to_python_progamming_ppt.ppt
Introductio_to_python_progamming_ppt.pptIntroductio_to_python_progamming_ppt.ppt
Introductio_to_python_progamming_ppt.ppt
 

Último

Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 

Último (20)

Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 

INTRODUCTION TO PYTHON.pptx

  • 2. Introduction to Python • Python is an interpreted, object-oriented, high-level programming language • Python's simple, easy to learn syntax emphasizes readability and therefore reduces the cost of program maintenance. • A standard distribution includes many modules • Dynamic typed Source can be compiled or run just-in-time Similar to perl, tcl, ruby
  • 3. Why Python • Python works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc). • Python has a simple syntax similar to the English language. • Python has syntax that allows developers to write programs with fewer lines than some other programming languages. • Python runs on an interpreter system, meaning that code can be executed as soon as it is written. This means that prototyping can be very quick. • Python can be treated in a procedural way, an object-oriented way or a functional way
  • 4. Python Interfaces IDLE : a cross-platform Python development Python Win: a Windows only interface to Python • Python Shell running 'python' from the Command Line opens this interactive shell
  • 5. IDLE — Development Environment • IDLE helps you program in Python by • color-coding your program code • debugging ' auto-indent ‘ • interactive shell Python Shell • Auto indent
  • 6. Example python Print (“Hello World”) output: Hello World
  • 7. Python Indentation • Indentation refers to the spaces at the beginning of a code line. • Where in other programming languages the indentation in code is for readability only, the indentation in Python is very important. • Python uses indentation to indicate a block of code. Example: if 5 > 2: print("Five is greater than two!")
  • 8. Python Comments • Comments can be used to explain Python code. • Comments can be used to make the code more readable. • Comments can be used to prevent execution when testing code Example #This is a comment print("Hello, World!")
  • 9. Python Variables • Variables are containers for storing data values • Python has no command for declaring a variable. • A variable is created the moment you first assign a value to it Example x = 5 y = "John" print(x) print(y)
  • 10. Python - Variable Names A variable can have a short name (like x and y) or a more descriptive name (age, carname, total_volume). Rules for Python variables: • A variable name must start with a letter or the underscore character • A variable name cannot start with a number • A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ) • Variable names are case-sensitive (age, Age and AGE are three different variables)
  • 11. Example • Legal variable names: myvar = "John" my_var = "John" _my_var = "John" myVar = "John" MYVAR = "John" myvar2 = "John"
  • 12. Python Variables - Assign Multiple Values Python allows you to assign values to multiple variables in one line: Example x, y, z = "Orange", "Banana", "Cherry" print(x) print(y) print(z)
  • 13. Python - Output Variables Python output variable function are print() Example x = "Python is awesome" print(x)
  • 14. Python - Global Variables • Variables that are created outside of a function (as in all of the examples above) are known as global variables. • Global variables can be used by everyone, both inside of functions and outside Example x = "awesome" def myfunc(): x = "fantastic" print("Python is " + x) myfunc() print("Python is " + x)
  • 15. Python Data Types • In programming, data type is an important concept. • 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
  • 16. Python Numbers • There are three Numeric types in python • Int • Float • Complex Example x = 1 # int y = 2.8 # float z = 1j # complex
  • 17. Python Casting There may be times when you want to specify a type on to a variable. This can be done with casting. Python is an object-orientated language, and as such it uses classes to define data types, including its primitive types. Casting in python is therefore done using constructor functions: • int() - constructs an integer number from an integer literal, a float literal (by removing all decimals), or a string literal (providing the string represents a whole number) • float() - constructs a float number from an integer literal, a float literal or a string literal (providing the string represents a float or an integer) • str() - constructs a string from a wide variety of data types, including strings, integer literals and float literals
  • 18. Example Integers: x = int(1) # x will be 1 y = int(2.8) # y will be 2 Floats: x = float(1) # x will be 1.0 y = float(2.8) # y will be 2.8 Strings: x = str("s1") # x will be 's1' y = str(2) # y will be '2
  • 19. Python Strings • Strings in python are surrounded by either single quotation marks, or double quotation marks. • 'hello' is the same as "hello“ Assign String to a Variable Assigning a string to a variable is done with the variable name followed by an equal sign and the string: Example a = "Hello" print(a)
  • 20. Python - Slicing Strings • You can return a range of characters by using the slice syntax. • Specify the start index and the end index, separated by a colon, to return a part of the string. Example Get the characters from position 2 to position 5 (not included): b = "Hello, World!" print(b[2:5]) Output llo
  • 21. Python - Modify Strings Python has a set of built-in methods that you can use on strings. Upper Case Example a = "Hello, World!" print(a.upper()) Output HELLO, WORLD! Lower Case a = "Hello, World!" print(a.lower()) OUTPUT Hello,world!
  • 22. Python - String Concatenation To concatenate, or combine, two strings you can use the + operator. a = "Hello" b = "World" c = a + b print(c) Python - Format – Strings age = 36 txt = "My name is John, and I am {}" print(txt.format(age)) Output My name is John, and I am 36
  • 23. Python Booleans Boolean represent true or false Example print(10 > 9) print(10 == 9) print(10 < 9) Output True False False
  • 24. Python Operators • Operators are used to perform operations on variables and values. Example print(10 + 5) Output 15 Python Lists Lists are used to store multiple items in a single variable thislist = ["apple", "banana", "cherry"] print(thislist)
  • 25. Python - Access List Items List items are indexed and you can access them by referring to the index number: Example Print the second item of the list: thislist = ["apple", "banana", "cherry"] print(thislist[1]) Python - Change List Items: To change the value of a specific item, refer to the index number: thislist = ["apple", "banana", "cherry"] thislist[1] = "blackcurrant" print(thislist)
  • 26. Python - Add List Items • To add an item to the end of the list, use the append() method thislist = ["apple", "banana", "cherry"] thislist.append("orange") print(thislist) Output ['apple', 'banana', 'cherry', 'orange']
  • 27. Python - Loop Lists • You can loop through the list by using for loop Example Print all items in the list, one by one: thislist = ["apple", "banana", "cherry"] for x in thislist: print(x) Output apple banana cherry
  • 28. Using a While Loop thislist = ["apple", "banana", "cherry"] i = 0 while i < len(thislist): print(thislist[i]) i = i + 1 Output apple banana cherry
  • 29. Python Tuples thistuple = ("apple", "banana", "cherry") print(thistuple) Python - Access Tuple Items You can access tuple items by referring to the index number, inside square brackets: Example Print the second item in the tuple: thistuple = ("apple", "banana", "cherry") print(thistuple[1])
  • 30. Python - Update Tuples • Once a tuple is created, you cannot change its values. Tuples are unchangeable, or immutable as it also is called. • But there is a workaround. You can convert the tuple into a list, change the list, and convert the list back into a tuple. Example Convert the tuple into a list to be able to change it: x = ("apple", "banana", "cherry") y = list(x) y[1] = "kiwi" x = tuple(y) print(x)
  • 31. Python Dictionaries thisdict = { "brand": "Ford", "model": "Mustang", "year": 1964 } Print(thisdict) Output {'brand': 'Ford', 'model': 'Mustang', 'year': 1964}
  • 32. Python Functions • A function is a block of code which only runs when it is called. • You can pass data, known as parameters, into a function. • A function can return data as a result Example def my_function(): print("Hello from a function") Output Hello from a function
  • 33. Python Lambda • A lambda function is a small anonymous function. • A lambda function can take any number of arguments, but can only have one expression. Example x = lambda a : a + 10 print(x(5)) Output 15
  • 34. Python Arrays • Arrays are used to store multiple values in one single variable: Example cars = ["Ford", "Volvo", "BMW"] Print(cars) Output ['Ford', 'Volvo', 'BMW']
  • 35. Python Classes and Objects • Python is an object oriented programming language. • Almost everything in Python is an object, with its properties and methods. • A Class is like an object constructor, or a "blueprint" for creating objects Example class MyClass: x = 5 p1 = MyClass() print(p1.x) Output 5
  • 36. The __init__() Function All classes have a function called __init__(), which is always executed when the class is being initiated. Example class Person: def __init__(self, name, age): self.name = name self.age = age p1 = Person("John", 36) print(p1.name) print(p1.age) Output John 36
  • 37. Python Inheritance • Inheritance allows us to define a class that inherits all the methods and properties from another class. Parent class is the class being inherited from, also called base class. Child class is the class that inherits from another class, also called derived class. class Person: def __init__(self, fname, lname): self.firstname = fname self.lastname = lname def printname(self): print(self.firstname, self.lastname) #Use the Person class to create an object, and then execute the printname method: x = Person("John", "Doe") x.printname() Output John Doe
  • 38. Python Math Python has a set of built-in math functions, including an extensive math module, that allows you to perform mathematical tasks on numbers. Example min,max: x = min(5, 10, 25) y = max(5, 10, 25) print(x) print(y)