Python-01| Fundamentals

Content
1. What is Python
2. Python Release
3. Application of Python
4. Features of Python
5. Tokens in Python
6. Comments in Python
7. Variables
1. What is Python?
Python is an interpreted, object-oriented, high-level
programming language for general-purpose(use for multi purpose
e.g. web app, desktop app, data science etc) programming. Created by
Guido van Rossum and first released in 1991.
Python is a cross-platform programming language,
meaning, it runs on multiple platforms like Windows, Mac
OS X, Linux, Unix.
Rossum was fan of a comedy series from late seventies.
The name "Python" was adopted from the same series
"Monty Python's Flying Circus".
2. Major release date of Python
Version Release date
Python 1.0 (Version) January 1994
Python 1.6 5 Sept 2000
Python 2.0 16 Oct 2000
Python 2.7 4 Jul 2010
Python 3.0 3 Dec 2008
Python 3.6.0 23 Dec 2016
Python 3.6.5 (Latest) 28 Mar 2018
3. Application of Python
Where we can use Python
 Desktop Application
 Web and Internet Application
 Database Application
 Networking Application
 Games
 Data Analysis (data science)
 Machine Learning
 Artificial Application
4. Features Of Python
 Simple and easy to learn
 It's much easier to read and write Python
programs compared to other languages like: C++,
Java, C#.
 Free and Open source
 You can freely use and distribute Python, even for
commercial use.
 Also you can able to see the source code and
even can make changes to the code.
Cont..
 High level programming language
 We are never required to worry about low level
activities like memory management, securities etc.
 Programming friendly language
 Platform Independent
• On any machine like widows, Linux or Mac we
are able to run the code anywhere
• We write code only once and can run on different
machine
• Write once and run anywhere (WORA)
Cont....
 Portability
 You can move Python programs from one
platform to another, and run it without any
changes.
Python
Program
written in
windows
Linux, MAC
etc
Portable
Think it as a mobile number portability, Airtel can be transferred to idea
operator without changing the phone number
Cont...
 Dynamically typed
 In python, there is no need to declare data type for
the variables, it internally create types, referring to the
values.
 C, C++ or Java are statically typed
 x = 10, python automatically assigns x as int
x = 10.5, python now accept it as float
x = True (now, type = Boolean)
so the variables are dynamically typed. In C or C++ or even in java if you
declare x as int then you cannot use it for a float value, if you do they
will through error
Cont....
 Object-Oriented
Python is object oriented as it supports
Class, Object, Data hiding, Data Encapsulated,
Polymorphism etc. It is also an procedural oriented as
we can make the program without classes if we don’t
need security.
C is procedural objected language but not
object-oriented
Java is Object-Oriented not procedural
because you can't code anything in Java without
declaring classes and objects.
Cont....
 Interpreted Language
when you run Python code, it automatically
converts your code to the language your computer
understands.You don't need to worry about any
lower-level operations.
It scans code line by line.
 Python is Extensible
You can easily combine pieces of C/C++ or other
languages with Python code.
We can improve the performance of the
application using this feature
5. Tokens
Individual words and punctuation marks are
called tokens or lexical units.
Python has following tokens:
5.1. Keywords
5.2. Identifiers (Name)
5.3. Literals
5.4. Operators
5.5. Punctuators
5.1. Keywords
 Keywords are the reserved words and convey
special meaning. Has 33 keywords
False assert del for in or while
True break elif from is pass with
None class else global lambda raise yield
and continue except if nonlocal return
as finally import not def try
5.2. Identifiers
 An identifier are the names to different part of the program
e.g. Variables, objects, classes, functions, list, dictionaries etc.
 Allowed symbols are (a to z), (A to Z), (0 to 9) and (_).
 Should not start with digits. (can be start by a letter or
underscore(_)).
 The digits ( 0 through 9) can be part of identifier except for
the first character
 Case-sensitive.
 Cannot use reserved words as identifiers.
 Identifiers are unlimited in length (no length limit).
 If any identifier starts with _ (e.g., _x) then this variable is
treated as private. If uses two (e.g., __x) then it is strongly
private
Cont...
 Valid identifier  Invalid Identifier
Myfile
myFile
_xy
_3
a2n56y
_chk
_3abc
My.file
2abc
$ab12
Data-rec
Break
a@abc
for
5.3. Literals/Values
Literals often referred to as constant-values
that have a fixed value.
Python allows several kinds of literals:
5.3.a. String literals
5.3.b. Numeric literals
5.3.c. Boolean literals
5.3.d. Special literal None
5.3.a. String literals
 String literal can be form by enclosing
text in single or double quotes
 E.g., ‘Arun’ ‘HelloWorld’ “112”
 Python allows two string types:
✓ Single line string
✓ Multi line string
Single line string Multi line string
 Terminate in one line
 E.g.,Text = ‘Hello’
 E.g.,Text = “Hello”
 Text = ‘hello
world’
Python will show you an
error
 Text spread across multiple
lines as one single string
 Can be created in two ways
either by triple quotation
mark (‘’’) or by backslash()
 E.g.,Text = ‘hello 
world’
Text = ‘’’this
Is another
multiline string’’’
Cont...
Multiline string literals can be created by two ways
either by triple quote(‘’’) or by backslash()
But the difference
This is only for the sake of
better readability in the
program. It doesn’t gives the
new line in the output, usually
uses in shell.
This is used when you have to
print multiple lines in output.
Gives output same as you write.
5.3.b. Numeric Literals
There are 3 numerical types
Int :- also called integers, are positive or negative whole
numbers with no decimal point (E.g., 2, -6). Int can be
represented in 4 ways and will be discuss in next slide.
Float :- represent real numbers and written with a
decimal point. (e.g., 17.5, -13.0)
Complex :- are of the form a + ib, where a and b are
floats and i =
One more numerical literal is Long which is used in 2.x but removed from
Python 3.
Cont...
int values further represented in 4 ways:
 Decimal values(Base 10): sequence of digits (0 to 9)
unless start with zero(e.g., 12, -7).
 Binary values(Base 2): sequence of only 1 and 0 , starts
with 0B or 0b (e.g., 0b1010).
 Octal values(Base 8): sequence of digits(0 to 7) starts
with 0O or 0o(zero-O) (e.g., 0o241)
 Hexadecimal values(Base 16):sequence of(0 to 9, a to
f,A to F) preceded by 0x or 0X(e.g., oxFace, oxBk9)
In Python 2.x, octal value can also be represented as preceded by only 0 or 0o
or 0O but preceding by only 0 will through an error in 3.x
5.3.c. Boolean Literal
A Boolean literal can either have True or
False.
5.3.d. Special literal None
The None literal in python means
“There’s nothing”
5.4. Operators
An Operator performs operation on data.
There are 7 operator in python
✓ Arithmetic operator
✓ Assignment operator
✓ Relational operator
✓ Logical operator
✓ Bitwise operator
✓ Membership operator
✓ Identity operator
We will learn more about operators in python in our next PPT
5.5. Punctuators
Punctuators are symbol/character that has
syntactic and semantic meaning to the compiler,
they are used in programming language to
organize sentence structure.
Most common punctuators in Python are:
‘ “ #  ( ) [ ] { } @ , : . = ; `
6. Comments in Python
Comments are additional readable information, which is
read by the programmers but ignored by Python
interpreter.
A single line comment can be inserted with #.
A multi line comment can be inserted with triple-
apostrophe(‘’’) or triple quotes(“””)
‘’’Multiline comments are useful for detailed additional information related to
the program.This type of multiline comment also known as docstring.
7. Variables
 Variable is a named location used to store data
in the memory
OR
Reserved memory location to store values.
 Each variable must have a unique name called
identifier. (discussed identifier in 5.2)
 Creating variable
MyName = “sajjad’
Cont...
 Variable is not created until some value is assigned to it.
 We can use the del statement to remove a variable
#Variable b is not assigned
Cont...
 In Python, variables do not need declaration to
reserve memory space this makes it dynamically
typed.
 “Variable declaration“ happens automatically
when we assign a value to a variable.
 Python create a variable of the type similar to
the type of value assigned.
E.g., age = 20
age is a numeric variable
Cont...
 In Python, program access data values through
references.
 A reference is a name that refers to the specific
location in memory of a value (object).
 Python internally create labels referring to
these values
Name
Age
 ‘sajjad’
 22
Cont...
5
1837884240
a
b
4
1837884224
Id is built in function use to get the address of an identifier.
Cont....
Multiple Assignments
 Assign same value to multiple variable
a = b = c = d = 10
 Assign multiple values to multiple variable
p, q, r = 5, 10, 7.5
 Expression separated with commas are evaluated
from left to right
E.g., x, x = 10, 12
print(x) #12
Cont...
EXAMPLE 1
EXAMPLE 2
Cont....
ProgramOutput
Cont....
Multiple assignment makes swapping easy
Cont...
DynamicType
For instance,
x = 10 #variable x is of int type
if you assign value of some other type to x, python will
not complain(no error)
x = 10
print(x)
x = ‘hello’ x
print(x)
Output will be:
10
hello
Int: 10
String: hello
X doesn’t have type but value it points to have type. So we can make variable
point to a value of different type.This is called dynamicTyping.
Cont....
To determine the type of a variable, we can use type() as:
type(<variable name>)
1 von 35

Recomendados

Python Functions von
Python   FunctionsPython   Functions
Python FunctionsMohammed Sikander
7.9K views21 Folien
Introduction to Python von
Introduction to Python Introduction to Python
Introduction to Python amiable_indian
36.8K views62 Folien
Programming with Python von
Programming with PythonProgramming with Python
Programming with PythonRasan Samarasinghe
6.2K views200 Folien
Python variables and data types.pptx von
Python variables and data types.pptxPython variables and data types.pptx
Python variables and data types.pptxAkshayAggarwal79
411 views210 Folien
Python programming : Strings von
Python programming : StringsPython programming : Strings
Python programming : StringsEmertxe Information Technologies Pvt Ltd
3.3K views26 Folien
Python Tutorial Part 1 von
Python Tutorial Part 1Python Tutorial Part 1
Python Tutorial Part 1Haitham El-Ghareeb
3.8K views76 Folien

Más contenido relacionado

Was ist angesagt?

Functions in python slide share von
Functions in python slide shareFunctions in python slide share
Functions in python slide shareDevashish Kumar
21.6K views20 Folien
Datatypes in python von
Datatypes in pythonDatatypes in python
Datatypes in pythoneShikshak
13.3K views35 Folien
11 Unit 1 Chapter 02 Python Fundamentals von
11  Unit 1 Chapter 02 Python Fundamentals11  Unit 1 Chapter 02 Python Fundamentals
11 Unit 1 Chapter 02 Python Fundamentalspraveenjigajinni
5.1K views153 Folien
Functions in Python von
Functions in PythonFunctions in Python
Functions in PythonKamal Acharya
3.2K views61 Folien
Python basics von
Python basicsPython basics
Python basicsRANAALIMAJEEDRAJPUT
2.5K views37 Folien
Variables & Data Types In Python | Edureka von
Variables & Data Types In Python | EdurekaVariables & Data Types In Python | Edureka
Variables & Data Types In Python | EdurekaEdureka!
2.1K views26 Folien

Was ist angesagt?(20)

Functions in python slide share von Devashish Kumar
Functions in python slide shareFunctions in python slide share
Functions in python slide share
Devashish Kumar21.6K views
Datatypes in python von eShikshak
Datatypes in pythonDatatypes in python
Datatypes in python
eShikshak13.3K views
11 Unit 1 Chapter 02 Python Fundamentals von praveenjigajinni
11  Unit 1 Chapter 02 Python Fundamentals11  Unit 1 Chapter 02 Python Fundamentals
11 Unit 1 Chapter 02 Python Fundamentals
praveenjigajinni5.1K views
Variables & Data Types In Python | Edureka von Edureka!
Variables & Data Types In Python | EdurekaVariables & Data Types In Python | Edureka
Variables & Data Types In Python | Edureka
Edureka!2.1K views
Python | What is Python | History of Python | Python Tutorial von QA TrainingHub
Python | What is Python | History of Python | Python TutorialPython | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python Tutorial
QA TrainingHub3.4K views
Fundamentals of Python Programming von Kamal Acharya
Fundamentals of Python ProgrammingFundamentals of Python Programming
Fundamentals of Python Programming
Kamal Acharya9.8K views
Arrays in python von moazamali28
Arrays in pythonArrays in python
Arrays in python
moazamali283.3K views

Similar a Python-01| Fundamentals

python ppt | Python Course In Ghaziabad | Scode Network Institute von
python ppt | Python Course In Ghaziabad | Scode Network Institutepython ppt | Python Course In Ghaziabad | Scode Network Institute
python ppt | Python Course In Ghaziabad | Scode Network InstituteScode Network Institute
54 views245 Folien
Python Introduction von
Python IntroductionPython Introduction
Python Introductionvikram mahendra
97 views43 Folien
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf von
python-online&offline-training-in-kphb-hyderabad (1) (1).pdfpython-online&offline-training-in-kphb-hyderabad (1) (1).pdf
python-online&offline-training-in-kphb-hyderabad (1) (1).pdfKosmikTech1
33 views208 Folien
Python unit1 von
Python unit1Python unit1
Python unit1charvi parth Lastpatel
109 views34 Folien
python von
pythonpython
pythonultragamer6
47 views20 Folien
Introduction to Python for Data Science and Machine Learning von
Introduction to Python for Data Science and Machine Learning Introduction to Python for Data Science and Machine Learning
Introduction to Python for Data Science and Machine Learning ParrotAI
566 views64 Folien

Similar a Python-01| Fundamentals(20)

python-online&offline-training-in-kphb-hyderabad (1) (1).pdf von KosmikTech1
python-online&offline-training-in-kphb-hyderabad (1) (1).pdfpython-online&offline-training-in-kphb-hyderabad (1) (1).pdf
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
KosmikTech133 views
Introduction to Python for Data Science and Machine Learning von ParrotAI
Introduction to Python for Data Science and Machine Learning Introduction to Python for Data Science and Machine Learning
Introduction to Python for Data Science and Machine Learning
ParrotAI566 views
Python introduction towards data science von deepak teja
Python introduction towards data sciencePython introduction towards data science
Python introduction towards data science
deepak teja131 views
Python - Module 1.ppt von jaba kumar
Python - Module 1.pptPython - Module 1.ppt
Python - Module 1.ppt
jaba kumar27 views
WEB PROGRAMMING UNIT VIII BY BHAVSINGH MALOTH von Bhavsingh Maloth
WEB PROGRAMMING UNIT VIII BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT VIII BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VIII BY BHAVSINGH MALOTH
Bhavsingh Maloth705 views
Python interview questions and answers von RojaPriya
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
RojaPriya149 views
Python Tutorial von AkramWaseem
Python TutorialPython Tutorial
Python Tutorial
AkramWaseem1.8K views
Python interview questions and answers von kavinilavuG
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
kavinilavuG118 views

Más de Mohd Sajjad

Python-04| Fundamental data types vs immutability von
Python-04| Fundamental data types vs immutabilityPython-04| Fundamental data types vs immutability
Python-04| Fundamental data types vs immutabilityMohd Sajjad
625 views18 Folien
Python-03| Data types von
Python-03| Data typesPython-03| Data types
Python-03| Data typesMohd Sajjad
2.2K views49 Folien
Python-02| Input, Output & Import von
Python-02| Input, Output & ImportPython-02| Input, Output & Import
Python-02| Input, Output & ImportMohd Sajjad
1.3K views30 Folien
Python-00 | Introduction and installing von
Python-00 | Introduction and installingPython-00 | Introduction and installing
Python-00 | Introduction and installingMohd Sajjad
306 views11 Folien
Secure your folder with password/without any software von
Secure your folder with password/without any softwareSecure your folder with password/without any software
Secure your folder with password/without any softwareMohd Sajjad
175 views10 Folien
SNMP Protocol von
SNMP ProtocolSNMP Protocol
SNMP ProtocolMohd Sajjad
561 views6 Folien

Más de Mohd Sajjad(6)

Python-04| Fundamental data types vs immutability von Mohd Sajjad
Python-04| Fundamental data types vs immutabilityPython-04| Fundamental data types vs immutability
Python-04| Fundamental data types vs immutability
Mohd Sajjad625 views
Python-03| Data types von Mohd Sajjad
Python-03| Data typesPython-03| Data types
Python-03| Data types
Mohd Sajjad2.2K views
Python-02| Input, Output & Import von Mohd Sajjad
Python-02| Input, Output & ImportPython-02| Input, Output & Import
Python-02| Input, Output & Import
Mohd Sajjad1.3K views
Python-00 | Introduction and installing von Mohd Sajjad
Python-00 | Introduction and installingPython-00 | Introduction and installing
Python-00 | Introduction and installing
Mohd Sajjad306 views
Secure your folder with password/without any software von Mohd Sajjad
Secure your folder with password/without any softwareSecure your folder with password/without any software
Secure your folder with password/without any software
Mohd Sajjad175 views

Último

2023Dec ASU Wang NETR Group Research Focus and Facility Overview.pptx von
2023Dec ASU Wang NETR Group Research Focus and Facility Overview.pptx2023Dec ASU Wang NETR Group Research Focus and Facility Overview.pptx
2023Dec ASU Wang NETR Group Research Focus and Facility Overview.pptxlwang78
165 views19 Folien
Design of Structures and Foundations for Vibrating Machines, Arya-ONeill-Pinc... von
Design of Structures and Foundations for Vibrating Machines, Arya-ONeill-Pinc...Design of Structures and Foundations for Vibrating Machines, Arya-ONeill-Pinc...
Design of Structures and Foundations for Vibrating Machines, Arya-ONeill-Pinc...csegroupvn
6 views210 Folien
sam_software_eng_cv.pdf von
sam_software_eng_cv.pdfsam_software_eng_cv.pdf
sam_software_eng_cv.pdfsammyigbinovia
9 views5 Folien
Web Dev Session 1.pptx von
Web Dev Session 1.pptxWeb Dev Session 1.pptx
Web Dev Session 1.pptxVedVekhande
13 views22 Folien
SUMIT SQL PROJECT SUPERSTORE 1.pptx von
SUMIT SQL PROJECT SUPERSTORE 1.pptxSUMIT SQL PROJECT SUPERSTORE 1.pptx
SUMIT SQL PROJECT SUPERSTORE 1.pptxSumit Jadhav
22 views26 Folien
START Newsletter 3 von
START Newsletter 3START Newsletter 3
START Newsletter 3Start Project
6 views25 Folien

Último(20)

2023Dec ASU Wang NETR Group Research Focus and Facility Overview.pptx von lwang78
2023Dec ASU Wang NETR Group Research Focus and Facility Overview.pptx2023Dec ASU Wang NETR Group Research Focus and Facility Overview.pptx
2023Dec ASU Wang NETR Group Research Focus and Facility Overview.pptx
lwang78165 views
Design of Structures and Foundations for Vibrating Machines, Arya-ONeill-Pinc... von csegroupvn
Design of Structures and Foundations for Vibrating Machines, Arya-ONeill-Pinc...Design of Structures and Foundations for Vibrating Machines, Arya-ONeill-Pinc...
Design of Structures and Foundations for Vibrating Machines, Arya-ONeill-Pinc...
csegroupvn6 views
Web Dev Session 1.pptx von VedVekhande
Web Dev Session 1.pptxWeb Dev Session 1.pptx
Web Dev Session 1.pptx
VedVekhande13 views
SUMIT SQL PROJECT SUPERSTORE 1.pptx von Sumit Jadhav
SUMIT SQL PROJECT SUPERSTORE 1.pptxSUMIT SQL PROJECT SUPERSTORE 1.pptx
SUMIT SQL PROJECT SUPERSTORE 1.pptx
Sumit Jadhav 22 views
REACTJS.pdf von ArthyR3
REACTJS.pdfREACTJS.pdf
REACTJS.pdf
ArthyR335 views
_MAKRIADI-FOTEINI_diploma thesis.pptx von fotinimakriadi
_MAKRIADI-FOTEINI_diploma thesis.pptx_MAKRIADI-FOTEINI_diploma thesis.pptx
_MAKRIADI-FOTEINI_diploma thesis.pptx
fotinimakriadi10 views
ASSIGNMENTS ON FUZZY LOGIC IN TRAFFIC FLOW.pdf von AlhamduKure
ASSIGNMENTS ON FUZZY LOGIC IN TRAFFIC FLOW.pdfASSIGNMENTS ON FUZZY LOGIC IN TRAFFIC FLOW.pdf
ASSIGNMENTS ON FUZZY LOGIC IN TRAFFIC FLOW.pdf
AlhamduKure6 views
fakenews_DBDA_Mar23.pptx von deepmitra8
fakenews_DBDA_Mar23.pptxfakenews_DBDA_Mar23.pptx
fakenews_DBDA_Mar23.pptx
deepmitra816 views
BCIC - Manufacturing Conclave - Technology-Driven Manufacturing for Growth von Innomantra
BCIC - Manufacturing Conclave -  Technology-Driven Manufacturing for GrowthBCIC - Manufacturing Conclave -  Technology-Driven Manufacturing for Growth
BCIC - Manufacturing Conclave - Technology-Driven Manufacturing for Growth
Innomantra 10 views
Ansari: Practical experiences with an LLM-based Islamic Assistant von M Waleed Kadous
Ansari: Practical experiences with an LLM-based Islamic AssistantAnsari: Practical experiences with an LLM-based Islamic Assistant
Ansari: Practical experiences with an LLM-based Islamic Assistant
M Waleed Kadous7 views
MongoDB.pdf von ArthyR3
MongoDB.pdfMongoDB.pdf
MongoDB.pdf
ArthyR349 views

Python-01| Fundamentals

  • 1. Content 1. What is Python 2. Python Release 3. Application of Python 4. Features of Python 5. Tokens in Python 6. Comments in Python 7. Variables
  • 2. 1. What is Python? Python is an interpreted, object-oriented, high-level programming language for general-purpose(use for multi purpose e.g. web app, desktop app, data science etc) programming. Created by Guido van Rossum and first released in 1991. Python is a cross-platform programming language, meaning, it runs on multiple platforms like Windows, Mac OS X, Linux, Unix. Rossum was fan of a comedy series from late seventies. The name "Python" was adopted from the same series "Monty Python's Flying Circus".
  • 3. 2. Major release date of Python Version Release date Python 1.0 (Version) January 1994 Python 1.6 5 Sept 2000 Python 2.0 16 Oct 2000 Python 2.7 4 Jul 2010 Python 3.0 3 Dec 2008 Python 3.6.0 23 Dec 2016 Python 3.6.5 (Latest) 28 Mar 2018
  • 4. 3. Application of Python Where we can use Python  Desktop Application  Web and Internet Application  Database Application  Networking Application  Games  Data Analysis (data science)  Machine Learning  Artificial Application
  • 5. 4. Features Of Python  Simple and easy to learn  It's much easier to read and write Python programs compared to other languages like: C++, Java, C#.  Free and Open source  You can freely use and distribute Python, even for commercial use.  Also you can able to see the source code and even can make changes to the code.
  • 6. Cont..  High level programming language  We are never required to worry about low level activities like memory management, securities etc.  Programming friendly language  Platform Independent • On any machine like widows, Linux or Mac we are able to run the code anywhere • We write code only once and can run on different machine • Write once and run anywhere (WORA)
  • 7. Cont....  Portability  You can move Python programs from one platform to another, and run it without any changes. Python Program written in windows Linux, MAC etc Portable Think it as a mobile number portability, Airtel can be transferred to idea operator without changing the phone number
  • 8. Cont...  Dynamically typed  In python, there is no need to declare data type for the variables, it internally create types, referring to the values.  C, C++ or Java are statically typed  x = 10, python automatically assigns x as int x = 10.5, python now accept it as float x = True (now, type = Boolean) so the variables are dynamically typed. In C or C++ or even in java if you declare x as int then you cannot use it for a float value, if you do they will through error
  • 9. Cont....  Object-Oriented Python is object oriented as it supports Class, Object, Data hiding, Data Encapsulated, Polymorphism etc. It is also an procedural oriented as we can make the program without classes if we don’t need security. C is procedural objected language but not object-oriented Java is Object-Oriented not procedural because you can't code anything in Java without declaring classes and objects.
  • 10. Cont....  Interpreted Language when you run Python code, it automatically converts your code to the language your computer understands.You don't need to worry about any lower-level operations. It scans code line by line.  Python is Extensible You can easily combine pieces of C/C++ or other languages with Python code. We can improve the performance of the application using this feature
  • 11. 5. Tokens Individual words and punctuation marks are called tokens or lexical units. Python has following tokens: 5.1. Keywords 5.2. Identifiers (Name) 5.3. Literals 5.4. Operators 5.5. Punctuators
  • 12. 5.1. Keywords  Keywords are the reserved words and convey special meaning. Has 33 keywords False assert del for in or while True break elif from is pass with None class else global lambda raise yield and continue except if nonlocal return as finally import not def try
  • 13. 5.2. Identifiers  An identifier are the names to different part of the program e.g. Variables, objects, classes, functions, list, dictionaries etc.  Allowed symbols are (a to z), (A to Z), (0 to 9) and (_).  Should not start with digits. (can be start by a letter or underscore(_)).  The digits ( 0 through 9) can be part of identifier except for the first character  Case-sensitive.  Cannot use reserved words as identifiers.  Identifiers are unlimited in length (no length limit).  If any identifier starts with _ (e.g., _x) then this variable is treated as private. If uses two (e.g., __x) then it is strongly private
  • 14. Cont...  Valid identifier  Invalid Identifier Myfile myFile _xy _3 a2n56y _chk _3abc My.file 2abc $ab12 Data-rec Break a@abc for
  • 15. 5.3. Literals/Values Literals often referred to as constant-values that have a fixed value. Python allows several kinds of literals: 5.3.a. String literals 5.3.b. Numeric literals 5.3.c. Boolean literals 5.3.d. Special literal None
  • 16. 5.3.a. String literals  String literal can be form by enclosing text in single or double quotes  E.g., ‘Arun’ ‘HelloWorld’ “112”  Python allows two string types: ✓ Single line string ✓ Multi line string
  • 17. Single line string Multi line string  Terminate in one line  E.g.,Text = ‘Hello’  E.g.,Text = “Hello”  Text = ‘hello world’ Python will show you an error  Text spread across multiple lines as one single string  Can be created in two ways either by triple quotation mark (‘’’) or by backslash()  E.g.,Text = ‘hello world’ Text = ‘’’this Is another multiline string’’’
  • 18. Cont... Multiline string literals can be created by two ways either by triple quote(‘’’) or by backslash() But the difference This is only for the sake of better readability in the program. It doesn’t gives the new line in the output, usually uses in shell. This is used when you have to print multiple lines in output. Gives output same as you write.
  • 19. 5.3.b. Numeric Literals There are 3 numerical types Int :- also called integers, are positive or negative whole numbers with no decimal point (E.g., 2, -6). Int can be represented in 4 ways and will be discuss in next slide. Float :- represent real numbers and written with a decimal point. (e.g., 17.5, -13.0) Complex :- are of the form a + ib, where a and b are floats and i = One more numerical literal is Long which is used in 2.x but removed from Python 3.
  • 20. Cont... int values further represented in 4 ways:  Decimal values(Base 10): sequence of digits (0 to 9) unless start with zero(e.g., 12, -7).  Binary values(Base 2): sequence of only 1 and 0 , starts with 0B or 0b (e.g., 0b1010).  Octal values(Base 8): sequence of digits(0 to 7) starts with 0O or 0o(zero-O) (e.g., 0o241)  Hexadecimal values(Base 16):sequence of(0 to 9, a to f,A to F) preceded by 0x or 0X(e.g., oxFace, oxBk9) In Python 2.x, octal value can also be represented as preceded by only 0 or 0o or 0O but preceding by only 0 will through an error in 3.x
  • 21. 5.3.c. Boolean Literal A Boolean literal can either have True or False. 5.3.d. Special literal None The None literal in python means “There’s nothing”
  • 22. 5.4. Operators An Operator performs operation on data. There are 7 operator in python ✓ Arithmetic operator ✓ Assignment operator ✓ Relational operator ✓ Logical operator ✓ Bitwise operator ✓ Membership operator ✓ Identity operator We will learn more about operators in python in our next PPT
  • 23. 5.5. Punctuators Punctuators are symbol/character that has syntactic and semantic meaning to the compiler, they are used in programming language to organize sentence structure. Most common punctuators in Python are: ‘ “ # ( ) [ ] { } @ , : . = ; `
  • 24. 6. Comments in Python Comments are additional readable information, which is read by the programmers but ignored by Python interpreter. A single line comment can be inserted with #. A multi line comment can be inserted with triple- apostrophe(‘’’) or triple quotes(“””) ‘’’Multiline comments are useful for detailed additional information related to the program.This type of multiline comment also known as docstring.
  • 25. 7. Variables  Variable is a named location used to store data in the memory OR Reserved memory location to store values.  Each variable must have a unique name called identifier. (discussed identifier in 5.2)  Creating variable MyName = “sajjad’
  • 26. Cont...  Variable is not created until some value is assigned to it.  We can use the del statement to remove a variable #Variable b is not assigned
  • 27. Cont...  In Python, variables do not need declaration to reserve memory space this makes it dynamically typed.  “Variable declaration“ happens automatically when we assign a value to a variable.  Python create a variable of the type similar to the type of value assigned. E.g., age = 20 age is a numeric variable
  • 28. Cont...  In Python, program access data values through references.  A reference is a name that refers to the specific location in memory of a value (object).  Python internally create labels referring to these values Name Age  ‘sajjad’  22
  • 29. Cont... 5 1837884240 a b 4 1837884224 Id is built in function use to get the address of an identifier.
  • 30. Cont.... Multiple Assignments  Assign same value to multiple variable a = b = c = d = 10  Assign multiple values to multiple variable p, q, r = 5, 10, 7.5  Expression separated with commas are evaluated from left to right E.g., x, x = 10, 12 print(x) #12
  • 34. Cont... DynamicType For instance, x = 10 #variable x is of int type if you assign value of some other type to x, python will not complain(no error) x = 10 print(x) x = ‘hello’ x print(x) Output will be: 10 hello Int: 10 String: hello X doesn’t have type but value it points to have type. So we can make variable point to a value of different type.This is called dynamicTyping.
  • 35. Cont.... To determine the type of a variable, we can use type() as: type(<variable name>)