SlideShare a Scribd company logo
1 of 23
Download to read offline
Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE
Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761
Fundamental Programming with Python
(Lecture # 02)
by
Muhammad Haroon
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.
Creating a Comment
Comments starts with a #, and Python will ignore them:
Example
#This is a comment
print("This is the first python program!")
Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE
Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761
Comments can be placed at the end of a line, and Python will ignore the rest of the line:
Example
print("This is the first python program!") #This is a comment
Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE
Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761
Comments does not have to be text to explain the code, it can also be used to prevent Python from
executing code:
Example
#print("Muhammad Haroon!")
print("Muhammad Haroon!")
Multi Line Comments
Python does not really have a syntax for multi line comments.
To add a multiline comment you could insert a # for each line:
Example
#This is a comment
#written in
#more than just one line
print("Muhammad Haroon!")
Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE
Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761
Or, not quite as intended, you can use a multiline string.
Since Python will ignore string literals that are not assigned to a variable, you can add a multiline string
(triple quotes) in your code, and place your comment inside it:
Example
"""
This is a comment
written in
more than just one line
"""
print("Muhammad Haroon!")
Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE
Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761
As long as the string is not assigned to a variable, Python will read the code, but then ignore it, and you
have made a multiline comment.
Python Variables
Creating Variables
Variables are containers for storing data values.
Unlike other programming languages, Python has no command for declaring a variable.
A variable is created the moment you first assign a value to it.
Example
x = 786
y = "Muhammad Haroon"
print(x)
print(y)
Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE
Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761
Variables do not need to be declared with any particular type and can even change type after they have
been set.
Example
x = 786 # x is of type int
x = "Muhammad Haroon" # x is now of type str
print(x)
Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE
Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761
String variables can be declared either by using single or double quotes:
Example
x = "Muhammad Haroon"
# is the same as
x = 'Muhammad Haroon'
Variable Names
A variable can have a short name (like x and y) or a more descriptive name (age, bikename, total_value).
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)
Python Data Types
Built-in 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
Binary Types: bytes, bytearray, memoryview
Getting the Data Type
You can get the data type of any object by using the type() function:
Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE
Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761
Example
Print the data type of the variable x:
x = 786
print(type(x))
Setting the Data Type
In Python, the data type is set when you assign a value to a variable:
Example Data Type Result
x = "Muhammad Haroon" str 01.py
x = 786 int 02.py
x = 20.5 float 03.py
x = 1j complex 04.py
x = ["apple", "banana", "cherry"] list 05.py
x = ("apple", "banana", "cherry") tuple 06.py
x = range(6) range 07.py
x = {"name" : "Muhammad Haroon", "age" : 27} dict 08.py
Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE
Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761
x = {"apple", "banana", "cherry"} set 09.py
x = frozenset({"apple", "banana", "cherry"}) frozenset 10.py
x = True bool 11.py
x = b"Muhammad Haroon" bytes 12.py
x = bytearray(5) bytearray 13.py
x = memoryview(bytes(5)) memoryview 14.py
Setting the Specific Data Type
If you want to specify the data type, you can use the following constructor functions:
Example Data Type Result
x = str("Muhammad Haroon") str 15.py
x = int(786) int 16.py
x = float(10.5) float 17.py
x = complex(1j) complex 18.py
x = list(("apple", "banana", "cherry")) list 19.py
x = tuple(("apple", "banana", "cherry")) tuple 20.py
x = range(6) range 21.py
x = dict(name="Muhammad Haroon", age=27) dict 22.py
x = set(("apple", "banana", "cherry")) set 23.py
x = frozenset(("apple", "banana", "cherry")) frozenset 24.py
x = bool(5) bool 25.py
x = bytes(5) bytes 26.py
x = bytearray(5) bytearray 27.py
x = memoryview(bytes(5)) memoryview 28.py
Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE
Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761
Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE
Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761
Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE
Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761
Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE
Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761
Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE
Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761
Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE
Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761
Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE
Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761
Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE
Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761
Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE
Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761
Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE
Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761
Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE
Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761
Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE
Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761
Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE
Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761
Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE
Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761
End

More Related Content

What's hot

Conformer-Kernel with Query Term Independence @ TREC 2020 Deep Learning Track
Conformer-Kernel with Query Term Independence @ TREC 2020 Deep Learning TrackConformer-Kernel with Query Term Independence @ TREC 2020 Deep Learning Track
Conformer-Kernel with Query Term Independence @ TREC 2020 Deep Learning TrackBhaskar Mitra
 
Bc0038– data structure using c
Bc0038– data structure using cBc0038– data structure using c
Bc0038– data structure using chayerpa
 
Dual Embedding Space Model (DESM)
Dual Embedding Space Model (DESM)Dual Embedding Space Model (DESM)
Dual Embedding Space Model (DESM)Bhaskar Mitra
 
Analysis of Similarity Measures between Short Text for the NTCIR-12 Short Tex...
Analysis of Similarity Measures between Short Text for the NTCIR-12 Short Tex...Analysis of Similarity Measures between Short Text for the NTCIR-12 Short Tex...
Analysis of Similarity Measures between Short Text for the NTCIR-12 Short Tex...KozoChikai
 
Language Models for Information Retrieval
Language Models for Information RetrievalLanguage Models for Information Retrieval
Language Models for Information RetrievalNik Spirin
 
Adversarial and reinforcement learning-based approaches to information retrieval
Adversarial and reinforcement learning-based approaches to information retrievalAdversarial and reinforcement learning-based approaches to information retrieval
Adversarial and reinforcement learning-based approaches to information retrievalBhaskar Mitra
 
5 Lessons Learned from Designing Neural Models for Information Retrieval
5 Lessons Learned from Designing Neural Models for Information Retrieval5 Lessons Learned from Designing Neural Models for Information Retrieval
5 Lessons Learned from Designing Neural Models for Information RetrievalBhaskar Mitra
 
Summary distributed representations_words_phrases
Summary distributed representations_words_phrasesSummary distributed representations_words_phrases
Summary distributed representations_words_phrasesYue Xiangnan
 
Computing with Directed Labeled Graphs
Computing with Directed Labeled GraphsComputing with Directed Labeled Graphs
Computing with Directed Labeled GraphsMarko Rodriguez
 
Bytewise Approximate Match: Theory, Algorithms and Applications
Bytewise Approximate Match:  Theory, Algorithms and ApplicationsBytewise Approximate Match:  Theory, Algorithms and Applications
Bytewise Approximate Match: Theory, Algorithms and ApplicationsLiwei Ren任力偉
 
Probabilistic Models of Novel Document Rankings for Faceted Topic Retrieval
Probabilistic Models of Novel Document Rankings for Faceted Topic RetrievalProbabilistic Models of Novel Document Rankings for Faceted Topic Retrieval
Probabilistic Models of Novel Document Rankings for Faceted Topic RetrievalYI-JHEN LIN
 
Tdm probabilistic models (part 2)
Tdm probabilistic  models (part  2)Tdm probabilistic  models (part  2)
Tdm probabilistic models (part 2)KU Leuven
 

What's hot (20)

Lecture20 xing
Lecture20 xingLecture20 xing
Lecture20 xing
 
Conformer-Kernel with Query Term Independence @ TREC 2020 Deep Learning Track
Conformer-Kernel with Query Term Independence @ TREC 2020 Deep Learning TrackConformer-Kernel with Query Term Independence @ TREC 2020 Deep Learning Track
Conformer-Kernel with Query Term Independence @ TREC 2020 Deep Learning Track
 
Final-Report
Final-ReportFinal-Report
Final-Report
 
Bc0038– data structure using c
Bc0038– data structure using cBc0038– data structure using c
Bc0038– data structure using c
 
Exposé Ontology
Exposé OntologyExposé Ontology
Exposé Ontology
 
Dual Embedding Space Model (DESM)
Dual Embedding Space Model (DESM)Dual Embedding Space Model (DESM)
Dual Embedding Space Model (DESM)
 
Analysis of Similarity Measures between Short Text for the NTCIR-12 Short Tex...
Analysis of Similarity Measures between Short Text for the NTCIR-12 Short Tex...Analysis of Similarity Measures between Short Text for the NTCIR-12 Short Tex...
Analysis of Similarity Measures between Short Text for the NTCIR-12 Short Tex...
 
OpenML NeurIPS2018
OpenML NeurIPS2018OpenML NeurIPS2018
OpenML NeurIPS2018
 
OpenML 2019
OpenML 2019OpenML 2019
OpenML 2019
 
Language Models for Information Retrieval
Language Models for Information RetrievalLanguage Models for Information Retrieval
Language Models for Information Retrieval
 
BDACA - Lecture3
BDACA - Lecture3BDACA - Lecture3
BDACA - Lecture3
 
BDACA - Lecture2
BDACA - Lecture2BDACA - Lecture2
BDACA - Lecture2
 
Learning how to learn
Learning how to learnLearning how to learn
Learning how to learn
 
Adversarial and reinforcement learning-based approaches to information retrieval
Adversarial and reinforcement learning-based approaches to information retrievalAdversarial and reinforcement learning-based approaches to information retrieval
Adversarial and reinforcement learning-based approaches to information retrieval
 
5 Lessons Learned from Designing Neural Models for Information Retrieval
5 Lessons Learned from Designing Neural Models for Information Retrieval5 Lessons Learned from Designing Neural Models for Information Retrieval
5 Lessons Learned from Designing Neural Models for Information Retrieval
 
Summary distributed representations_words_phrases
Summary distributed representations_words_phrasesSummary distributed representations_words_phrases
Summary distributed representations_words_phrases
 
Computing with Directed Labeled Graphs
Computing with Directed Labeled GraphsComputing with Directed Labeled Graphs
Computing with Directed Labeled Graphs
 
Bytewise Approximate Match: Theory, Algorithms and Applications
Bytewise Approximate Match:  Theory, Algorithms and ApplicationsBytewise Approximate Match:  Theory, Algorithms and Applications
Bytewise Approximate Match: Theory, Algorithms and Applications
 
Probabilistic Models of Novel Document Rankings for Faceted Topic Retrieval
Probabilistic Models of Novel Document Rankings for Faceted Topic RetrievalProbabilistic Models of Novel Document Rankings for Faceted Topic Retrieval
Probabilistic Models of Novel Document Rankings for Faceted Topic Retrieval
 
Tdm probabilistic models (part 2)
Tdm probabilistic  models (part  2)Tdm probabilistic  models (part  2)
Tdm probabilistic models (part 2)
 

Similar to Lecture02 - Fundamental Programming with Python Language

Python ppt.pdf
Python ppt.pdfPython ppt.pdf
Python ppt.pdfkalai75
 
Building yourself with Python - Learn the Basics!!
Building yourself with Python - Learn the Basics!!Building yourself with Python - Learn the Basics!!
Building yourself with Python - Learn the Basics!!FRANKLINODURO
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to pythonRucha Gokhale
 
Python (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualizePython (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualizeIruolagbePius
 
Python programming report demo for all the students
Python programming report demo for all the studentsPython programming report demo for all the students
Python programming report demo for all the studentsplanetarcadia56
 
FDP-faculty deveopmemt program on python
FDP-faculty deveopmemt program on pythonFDP-faculty deveopmemt program on python
FDP-faculty deveopmemt program on pythonkannikadg
 
C# programming : Chapter One
C# programming : Chapter OneC# programming : Chapter One
C# programming : Chapter OneKhairi Aiman
 
Python - An Introduction
Python - An IntroductionPython - An Introduction
Python - An IntroductionSwarit Wadhe
 
Introduction to python & its applications.ppt
Introduction to python & its applications.pptIntroduction to python & its applications.ppt
Introduction to python & its applications.pptPradeepNB2
 
unit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptxunit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptxusvirat1805
 
applications and advantages of python
applications and advantages of pythonapplications and advantages of python
applications and advantages of pythonbhavesh lande
 
slides1-introduction to python-programming.pptx
slides1-introduction to python-programming.pptxslides1-introduction to python-programming.pptx
slides1-introduction to python-programming.pptxAkhdanMumtaz
 
Introduction to Python and Matplotlib
Introduction to Python and MatplotlibIntroduction to Python and Matplotlib
Introduction to Python and MatplotlibFrançois Bianco
 
Zero to Hero - Introduction to Python3
Zero to Hero - Introduction to Python3Zero to Hero - Introduction to Python3
Zero to Hero - Introduction to Python3Chariza Pladin
 
Python basics_ part1
Python basics_ part1Python basics_ part1
Python basics_ part1Elaf A.Saeed
 

Similar to Lecture02 - Fundamental Programming with Python Language (20)

Python ppt.pdf
Python ppt.pdfPython ppt.pdf
Python ppt.pdf
 
Building yourself with Python - Learn the Basics!!
Building yourself with Python - Learn the Basics!!Building yourself with Python - Learn the Basics!!
Building yourself with Python - Learn the Basics!!
 
Python fundamentals
Python fundamentalsPython fundamentals
Python fundamentals
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Python (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualizePython (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualize
 
Python programming report demo for all the students
Python programming report demo for all the studentsPython programming report demo for all the students
Python programming report demo for all the students
 
FDP-faculty deveopmemt program on python
FDP-faculty deveopmemt program on pythonFDP-faculty deveopmemt program on python
FDP-faculty deveopmemt program on python
 
C# programming : Chapter One
C# programming : Chapter OneC# programming : Chapter One
C# programming : Chapter One
 
Presentation 1 (1).pdf
Presentation 1 (1).pdfPresentation 1 (1).pdf
Presentation 1 (1).pdf
 
Python - An Introduction
Python - An IntroductionPython - An Introduction
Python - An Introduction
 
Python 3.x quick syntax guide
Python 3.x quick syntax guidePython 3.x quick syntax guide
Python 3.x quick syntax guide
 
Introduction to python & its applications.ppt
Introduction to python & its applications.pptIntroduction to python & its applications.ppt
Introduction to python & its applications.ppt
 
unit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptxunit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptx
 
applications and advantages of python
applications and advantages of pythonapplications and advantages of python
applications and advantages of python
 
slides1-introduction to python-programming.pptx
slides1-introduction to python-programming.pptxslides1-introduction to python-programming.pptx
slides1-introduction to python-programming.pptx
 
Python for dummies
Python for dummiesPython for dummies
Python for dummies
 
Introduction to Python and Matplotlib
Introduction to Python and MatplotlibIntroduction to Python and Matplotlib
Introduction to Python and Matplotlib
 
Zero to Hero - Introduction to Python3
Zero to Hero - Introduction to Python3Zero to Hero - Introduction to Python3
Zero to Hero - Introduction to Python3
 
Python basics_ part1
Python basics_ part1Python basics_ part1
Python basics_ part1
 
Python programming language
Python programming languagePython programming language
Python programming language
 

More from National College of Business Administration & Economics ( NCBA&E)

More from National College of Business Administration & Economics ( NCBA&E) (20)

Lecturre 07 - Chapter 05 - Basic Communications Operations
Lecturre 07 - Chapter 05 - Basic Communications  OperationsLecturre 07 - Chapter 05 - Basic Communications  Operations
Lecturre 07 - Chapter 05 - Basic Communications Operations
 
Lecture 05 - Chapter 03 - Examples
Lecture 05 - Chapter 03 - ExamplesLecture 05 - Chapter 03 - Examples
Lecture 05 - Chapter 03 - Examples
 
Lecture # 02 - OOP with Python Language by Muhammad Haroon
Lecture # 02 - OOP with Python Language by Muhammad HaroonLecture # 02 - OOP with Python Language by Muhammad Haroon
Lecture # 02 - OOP with Python Language by Muhammad Haroon
 
Lecture 06 - Chapter 4 - Communications in Networks
Lecture 06 - Chapter 4 - Communications in NetworksLecture 06 - Chapter 4 - Communications in Networks
Lecture 06 - Chapter 4 - Communications in Networks
 
Lecture 01 - Basic Concept About OOP With Python
Lecture 01 - Basic Concept About OOP With PythonLecture 01 - Basic Concept About OOP With Python
Lecture 01 - Basic Concept About OOP With Python
 
Lecture 05 - Chapter 3 - Models of parallel computers and interconnections
Lecture 05 - Chapter 3 - Models of parallel computers and  interconnectionsLecture 05 - Chapter 3 - Models of parallel computers and  interconnections
Lecture 05 - Chapter 3 - Models of parallel computers and interconnections
 
Lecture01 Part(B) - Installing Visual Studio Code On All Version Of Windows O...
Lecture01 Part(B) - Installing Visual Studio Code On All Version Of Windows O...Lecture01 Part(B) - Installing Visual Studio Code On All Version Of Windows O...
Lecture01 Part(B) - Installing Visual Studio Code On All Version Of Windows O...
 
Lecture01 - Fundamental Programming with Python Language
Lecture01 - Fundamental Programming with Python LanguageLecture01 - Fundamental Programming with Python Language
Lecture01 - Fundamental Programming with Python Language
 
Lecture 04 (Part 01) - Measure of Location
Lecture 04 (Part 01) - Measure of LocationLecture 04 (Part 01) - Measure of Location
Lecture 04 (Part 01) - Measure of Location
 
Lecture 04 chapter 2 - Parallel Programming Platforms
Lecture 04  chapter 2 - Parallel Programming PlatformsLecture 04  chapter 2 - Parallel Programming Platforms
Lecture 04 chapter 2 - Parallel Programming Platforms
 
Lecture 04 Chapter 1 - Introduction to Parallel Computing
Lecture 04  Chapter 1 - Introduction to Parallel ComputingLecture 04  Chapter 1 - Introduction to Parallel Computing
Lecture 04 Chapter 1 - Introduction to Parallel Computing
 
Lecture 03 Part 02 - All Examples of Chapter 02 by Muhammad Haroon
Lecture 03 Part 02 - All Examples of Chapter 02 by Muhammad HaroonLecture 03 Part 02 - All Examples of Chapter 02 by Muhammad Haroon
Lecture 03 Part 02 - All Examples of Chapter 02 by Muhammad Haroon
 
Lecture 03 - Chapter 02 - Part 02 - Probability & Statistics by Muhammad Haroon
Lecture 03 - Chapter 02 - Part 02 - Probability & Statistics by Muhammad HaroonLecture 03 - Chapter 02 - Part 02 - Probability & Statistics by Muhammad Haroon
Lecture 03 - Chapter 02 - Part 02 - Probability & Statistics by Muhammad Haroon
 
Lecture 03 - Synchronous and Asynchronous Communication - Concurrency - Fault...
Lecture 03 - Synchronous and Asynchronous Communication - Concurrency - Fault...Lecture 03 - Synchronous and Asynchronous Communication - Concurrency - Fault...
Lecture 03 - Synchronous and Asynchronous Communication - Concurrency - Fault...
 
Lecture 03 - Chapter 02 - Part 01 - Probability & Statistics by Muhammad Haroon
Lecture 03 - Chapter 02 - Part 01 - Probability & Statistics by Muhammad HaroonLecture 03 - Chapter 02 - Part 01 - Probability & Statistics by Muhammad Haroon
Lecture 03 - Chapter 02 - Part 01 - Probability & Statistics by Muhammad Haroon
 
Lecture 02 - Chapter 01 - Probability & Statistics by Muhammad Haroon
Lecture 02 - Chapter 01 - Probability & Statistics by Muhammad HaroonLecture 02 - Chapter 01 - Probability & Statistics by Muhammad Haroon
Lecture 02 - Chapter 01 - Probability & Statistics by Muhammad Haroon
 
Lecture 02 - Chapter 1 (Part 02): Grid/Cloud Computing Systems, Cluster Comp...
Lecture 02 - Chapter 1 (Part 02):  Grid/Cloud Computing Systems, Cluster Comp...Lecture 02 - Chapter 1 (Part 02):  Grid/Cloud Computing Systems, Cluster Comp...
Lecture 02 - Chapter 1 (Part 02): Grid/Cloud Computing Systems, Cluster Comp...
 
Lecture 01 - Chapter 1 (Part 01): Some basic concept of Operating System (OS)...
Lecture 01 - Chapter 1 (Part 01): Some basic concept of Operating System (OS)...Lecture 01 - Chapter 1 (Part 01): Some basic concept of Operating System (OS)...
Lecture 01 - Chapter 1 (Part 01): Some basic concept of Operating System (OS)...
 
WHO director-general's opening remarks at the media briefing on covid-19 - 23...
WHO director-general's opening remarks at the media briefing on covid-19 - 23...WHO director-general's opening remarks at the media briefing on covid-19 - 23...
WHO director-general's opening remarks at the media briefing on covid-19 - 23...
 
Course outline of parallel and distributed computing
Course outline of parallel and distributed computingCourse outline of parallel and distributed computing
Course outline of parallel and distributed computing
 

Recently uploaded

Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint23600690
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjMohammed Sikander
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....Ritu480198
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...EduSkills OECD
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code ExamplesPeter Brusilovsky
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaEADTU
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽中 央社
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismDabee Kamal
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFVivekanand Anglo Vedic Academy
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportDenish Jangid
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppCeline George
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptNishitharanjan Rout
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfPondicherry University
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital ManagementMBA Assignment Experts
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...Nguyen Thanh Tu Collection
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文中 央社
 

Recently uploaded (20)

Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 

Lecture02 - Fundamental Programming with Python Language

  • 1. Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761 Fundamental Programming with Python (Lecture # 02) by Muhammad Haroon 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. Creating a Comment Comments starts with a #, and Python will ignore them: Example #This is a comment print("This is the first python program!")
  • 2. Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761 Comments can be placed at the end of a line, and Python will ignore the rest of the line: Example print("This is the first python program!") #This is a comment
  • 3. Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761 Comments does not have to be text to explain the code, it can also be used to prevent Python from executing code: Example #print("Muhammad Haroon!") print("Muhammad Haroon!") Multi Line Comments Python does not really have a syntax for multi line comments. To add a multiline comment you could insert a # for each line: Example #This is a comment #written in #more than just one line print("Muhammad Haroon!")
  • 4. Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761 Or, not quite as intended, you can use a multiline string. Since Python will ignore string literals that are not assigned to a variable, you can add a multiline string (triple quotes) in your code, and place your comment inside it: Example """ This is a comment written in more than just one line """ print("Muhammad Haroon!")
  • 5. Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761 As long as the string is not assigned to a variable, Python will read the code, but then ignore it, and you have made a multiline comment. Python Variables Creating Variables Variables are containers for storing data values. Unlike other programming languages, Python has no command for declaring a variable. A variable is created the moment you first assign a value to it. Example x = 786 y = "Muhammad Haroon" print(x) print(y)
  • 6. Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761 Variables do not need to be declared with any particular type and can even change type after they have been set. Example x = 786 # x is of type int x = "Muhammad Haroon" # x is now of type str print(x)
  • 7. Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761 String variables can be declared either by using single or double quotes: Example x = "Muhammad Haroon" # is the same as x = 'Muhammad Haroon' Variable Names A variable can have a short name (like x and y) or a more descriptive name (age, bikename, total_value). 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) Python Data Types Built-in 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 Binary Types: bytes, bytearray, memoryview Getting the Data Type You can get the data type of any object by using the type() function:
  • 8. Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761 Example Print the data type of the variable x: x = 786 print(type(x)) Setting the Data Type In Python, the data type is set when you assign a value to a variable: Example Data Type Result x = "Muhammad Haroon" str 01.py x = 786 int 02.py x = 20.5 float 03.py x = 1j complex 04.py x = ["apple", "banana", "cherry"] list 05.py x = ("apple", "banana", "cherry") tuple 06.py x = range(6) range 07.py x = {"name" : "Muhammad Haroon", "age" : 27} dict 08.py
  • 9. Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761 x = {"apple", "banana", "cherry"} set 09.py x = frozenset({"apple", "banana", "cherry"}) frozenset 10.py x = True bool 11.py x = b"Muhammad Haroon" bytes 12.py x = bytearray(5) bytearray 13.py x = memoryview(bytes(5)) memoryview 14.py Setting the Specific Data Type If you want to specify the data type, you can use the following constructor functions: Example Data Type Result x = str("Muhammad Haroon") str 15.py x = int(786) int 16.py x = float(10.5) float 17.py x = complex(1j) complex 18.py x = list(("apple", "banana", "cherry")) list 19.py x = tuple(("apple", "banana", "cherry")) tuple 20.py x = range(6) range 21.py x = dict(name="Muhammad Haroon", age=27) dict 22.py x = set(("apple", "banana", "cherry")) set 23.py x = frozenset(("apple", "banana", "cherry")) frozenset 24.py x = bool(5) bool 25.py x = bytes(5) bytes 26.py x = bytearray(5) bytearray 27.py x = memoryview(bytes(5)) memoryview 28.py
  • 10. Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761
  • 11. Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761
  • 12. Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761
  • 13. Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761
  • 14. Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761
  • 15. Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761
  • 16. Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761
  • 17. Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761
  • 18. Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761
  • 19. Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761
  • 20. Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761
  • 21. Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761
  • 22. Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761
  • 23. Fundamental Programming with Python mr.harunahmad2014@gmail.com CS/IT/SE/CSE Muhammad Haroon – PhD CS (Enrolled) from Hitec University Taxila 0300-7327761 End