SlideShare a Scribd company logo
1
CHAPTER 1
Introduction and Syntax of
Python programming
2
Features of Python
• Simple
• Easy to Learn
• Versatile
• Free and Open Source
• High-level Language
• Interactive
• Portable
• Object Oriented
• Interpreted
• Dynamic
• Extensible
• Embeddable
• Extensive
• Easy maintenance
• Secure
• Robust
• Multi-threaded
• Garbage Collection
Applications of Python
3
• Embedded scripting language: Python is used as an embedded scripting language for various testing/
building/ deployment/ monitoring frameworks, scientific apps, and quick scripts.
• 3D Software: 3D software like Maya uses Python for automating small user tasks, or for doing more
complex integration such as talking to databases and asset management systems.
• Web development: Python is an easily extensible language that provides good integration with database
and other web standards.
GUI-based desktop applications: Simple syntax, modular architecture, rich text processing tools and the
ability to work on multiple operating systems makes Python a preferred choice for developing desktop-
based applications.
• Image processing and graphic design applications: Python is used to make 2D imaging software such as
Inkscape, GIMP, Paint Shop Pro and Scribus. It is also used to make 3D animation packages, like Blender,
3ds Max, Cinema 4D, Houdini, Lightwave and Maya.
4
Applications of Python
• Scientific and computational applications: Features like high speed, productivity and availability of tools,
such as Scientific Python and Numeric Python, have made Python a preferred language to perform
computation and processing of scientific data. 3D modeling software, such as FreeCAD, and finite element
method software, like Abaqus, are coded in Python.
Games: Python has various modules, libraries, and platforms that support development of games. Games
like Civilization-IV, Disney'sToontown Online,Vega Strike, etc. are coded using Python.
• Enterprise and business applications: Simple and reliable syntax, modules and libraries, extensibility,
scalability together make Python a suitable coding language for customizing larger applications. For
example, Reddit which was originally written in Common Lips, was rewritten in Python in 2005. A large
part of Youtube code is also written in Python.
• Operating Systems: Python forms an integral part of Linux distributions.
5
Writing and Executing First Python Program
Step 1: Open an editor.
Step 2: Write the instructions
Step 3: Save it as a file with the filename having the extension .py.
Step 4: Run the interpreter with the command python program_name.py or use IDLE to run the
programs.
To execute the program at the command prompt, simply change your working directory to C:Python34
(or move to the directory where you have saved Python) then type python program_name.py.
If you want to execute the program in Python shell, then just press F5 key or click on Run Menu and then
select Run Module.
6
Types of mode:
A. Interactive mode
B. Script Mode
A. Interactive Mode:
In the interactive mode as we enter a command and press enter, the very next step we get the
output. The output of the code in the interactive mode is influenced by the last command we give.
Interactive mode is very convenient for writing very short lines of code.
print(“Hello”)
Disadvantages of Interactive mode:
• The interactive mode is not suitable for large programs.
• The interactive mode doesn’t save the statements. Once we make a program it is for that time itself,
we cannot use it in the future. In order to use it in the future, we need to retype all the statements.
• Editing the code written in interactive mode is a tedious task.We need to revisit all our previous
commands and if still, we could not edit we need to type everything again.
Modes in Python
7
B. Script Mode:
In the script mode, a python program can be written in a file.This file can then be saved and
executed using the command prompt.We can view the code at any time by opening the file and editing
becomes quite easy as we can open and view the entire code as many times as we want.
8
9
Literal Constants
The value of a literal constant can be used directly in programs. For example, 7, 3.9, 'A', and "Hello" are
literal constants.
Numbers refers to a numeric value.You can use four types of numbers in Python program- integers, long
integers, floating point and complex numbers.
• Numbers like 5 or other whole numbers are referred to as integers. Bigger whole numbers are called long
integers. For example, 535633629843L is a long integer.
• Numbers like are 3.23 and 91.5E-2 are termed as floating point numbers.
• Numbers of a + bi form (like -3 + 7i) are complex numbers.
Examples:
10
Literal Constants
Strings
A string is a group of characters.
• Using Single Quotes ('): For example, a string can be written as 'HELLO'.
• Using Double Quotes ("): Strings in double quotes are exactly same as those in single quotes.Therefore,
'HELLO' is same as "HELLO".
• UsingTriple Quotes (''' '''): You can specify multi-line strings using triple quotes.You can use as many single
quotes and double quotes as you want in a string within triple quotes.
Examples:
11
print("Welcome to Python Programming Language")
print('Welcome to Python Programming Language')
print('''Welcome to Python
Programming Language''')
12
Escape Sequences
Some characters (like ", ) cannot be directly included in a string. Such characters must be escaped by
placing a backslash before them.
Example:
13
Raw Strings
If you want to specify a string that should not handle any escape sequences and want to display exactly as
specified then you need to specify that string as a raw string. A raw string is specified by prefixing r or R to
the string.
Example:
14
print("HinHello")
print(r"HinHello")
print("n")
print("Hi'Hello")
print(r"Hi'Hello")
print("n")
print("HiHello")
print(R"HiHello")
15
Variables and Identifiers
Variable means its value can vary. You can store any piece of information in a variable. Variables are
nothing but just parts of your computer’s memory where information is stored.To be identified easily,
each variable is given an appropriate name.
Identifiers are names given to identify something. This something can be a variable, function, class,
module or other object. For naming any identifier, there are some basic rules like:
• The first character of an identifier must be an underscore ('_') or a letter (upper or lowercase).
• The rest of the identifier name can be underscores ('_'), letters (upper or lowercase), or digits (0-9).
• Identifier names are case-sensitive. For example, myvar and myVar are not the same.
• Punctuation characters such as @, $, and % are not allowed within identifiers.
Examples of valid identifier names are sum, __my_var, num1, r, var_20, First, etc.
Examples of invalid identifier names are 1num, my-var, %check, Basic Sal, H#R&A, etc.
16
Assigning or InitializingValues toVariables
In Python, programmers need not explicitly declare variables to reserve memory space.The declaration is
done automatically when a value is assigned to the variable using the equal sign (=).The operand on the left
side of equal sign is the name of the variable and the operand on its right side is the value to be stored in
that variable.
Example:
17
s="Python"
a=100
b=10.5
c=5+3j
print("sting="+s)
print("int number="+str(a))
print("float number="+str(b))
print("complex number="+str(c))
print("nn")
a,b,c=100,10.5,5+3j
print("sting="+s)
print("int number="+str(a))
print("float number="+str(b))
print("complex number="+str(c))
print("nn")
a=b=c=0
print(a)
print(b)
print(c)
18
Comments
Comments are the non-executable statements in a program. They are just
added to describe the statements in the program code. Comments make the
program easily readable and understandable by the programmer as well as
other users who are seeing the code. The interpreter simply ignores the
comments.
19
1. Single Line Comments: In Python for single line comments use # sign to
comment out everything following it on that line.
2. Multiple Lines Comments: Multiple lines comments are slightly different.
Simply use 3 single quotes before and after the part you want to be
commented.
Example:
#This is comment
#print("Statement will not be executed")
print("Statement will be excuted")
'''print("Multiple line comment")
print("Multiple line comment")
print("Multiple line comment")'''
20
Input Operation
To take input from the users, Python makes use of the input() function.The input() function prompts the
user to provide some information on which the program can work and give the result. However, we must
always remember that the input function takes user’s input as a string.
Example:
21
a=input("Enter a number")
b=input("Enter a number")
print(a+b)
a=int(input("Enter a number"))
b=int(input("Enter a number"))
print(a+b)
22
a=float(input("Enter a number"))
b=float(input("Enter a number"))
print(a+b)
a=complex(input("Enter a number"))
b=complex(input("Enter a number"))
print(a+b)
23
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
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:
DataType
24
x = str("Hello World") str
x = int(20) int
x = float(20.5) float
x = complex(1j) complex
x = list(("apple", "banana",
"cherry"))
list
x = tuple(("apple", "banana",
"cherry"))
tuple
x = range(6) range
x = dict(name="John",
age=36)
dict
x = set(("apple", "banana", "cherry")) set
x = frozenset(("apple", "banana",
"cherry"))
frozenset
x = bool(5) bool
Examples:
25
x = bytes(5) bytes
x = bytearray(5) bytearray
x = memoryview(bytes(5)) memoryview
26
Boolean Values
-In programming you often need to know if an expression is True or False.
-You can evaluate any expression in Python, and get one of two answers, True or False.
-When you compare two values, the expression is evaluated and Python returns the
Boolean answer:
print(10 > 9)
print(10 == 9)
print(10 < 9)

More Related Content

PPTX
Python basics
ssuser4e32df
 
PPTX
Introduction to Python Basics for PSSE Integration
FarhanKhan978284
 
PPTX
python_class.pptx
chandankumar943868
 
PDF
PART - 1 Python Introduction- Variables- Data types - Numeric- String- Boole...
manikamr074
 
PPTX
Introduction to Python Programming .pptx
NaynaSagarDahatonde
 
PPT
Python - Module 1.ppt
jaba kumar
 
PPTX
Python (Data Analysis) cleaning and visualize
IruolagbePius
 
PPTX
Python 01.pptx
AliMohammadAmiri
 
Python basics
ssuser4e32df
 
Introduction to Python Basics for PSSE Integration
FarhanKhan978284
 
python_class.pptx
chandankumar943868
 
PART - 1 Python Introduction- Variables- Data types - Numeric- String- Boole...
manikamr074
 
Introduction to Python Programming .pptx
NaynaSagarDahatonde
 
Python - Module 1.ppt
jaba kumar
 
Python (Data Analysis) cleaning and visualize
IruolagbePius
 
Python 01.pptx
AliMohammadAmiri
 

Similar to Chapter 1-Introduction and syntax of python programming.pptx (20)

PDF
Tutorial on-python-programming
Chetan Giridhar
 
PPTX
presentation_python_7_1569170870_375360.pptx
ansariparveen06
 
PPT
Python
Kumar Gaurav
 
PPTX
Introduction-to-Python-Programming1.pptx
vijayalakshmi257551
 
PPTX
#Code2Create: Python Basics
GDGKuwaitGoogleDevel
 
PDF
Sessisgytcfgggggggggggggggggggggggggggggggg
pawankamal3
 
PPTX
Introduction to python
MaheshPandit16
 
PPTX
PYTHON PROGRAMMING.pptx
swarna627082
 
PDF
Python basics_ part1
Elaf A.Saeed
 
PPTX
Chapter1 python introduction syntax general
ssuser77162c
 
PPTX
python ppt | Python Course In Ghaziabad | Scode Network Institute
Scode Network Institute
 
PDF
Python Programming
Saravanan T.M
 
PPTX
introduction to python
Jincy Nelson
 
PPTX
Python Programming for problem solving.pptx
NishaM41
 
PPTX
Chapter7-Introduction to Python.pptx
lemonchoos
 
PPTX
UNIT 1 .pptx
Prachi Gawande
 
PPTX
introduction to python programming concepts
GautamDharamrajChouh
 
PDF
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
KosmikTech1
 
PPTX
2. Getting Started with Python second lesson .pptx
Primary2Primary2
 
Tutorial on-python-programming
Chetan Giridhar
 
presentation_python_7_1569170870_375360.pptx
ansariparveen06
 
Python
Kumar Gaurav
 
Introduction-to-Python-Programming1.pptx
vijayalakshmi257551
 
#Code2Create: Python Basics
GDGKuwaitGoogleDevel
 
Sessisgytcfgggggggggggggggggggggggggggggggg
pawankamal3
 
Introduction to python
MaheshPandit16
 
PYTHON PROGRAMMING.pptx
swarna627082
 
Python basics_ part1
Elaf A.Saeed
 
Chapter1 python introduction syntax general
ssuser77162c
 
python ppt | Python Course In Ghaziabad | Scode Network Institute
Scode Network Institute
 
Python Programming
Saravanan T.M
 
introduction to python
Jincy Nelson
 
Python Programming for problem solving.pptx
NishaM41
 
Chapter7-Introduction to Python.pptx
lemonchoos
 
UNIT 1 .pptx
Prachi Gawande
 
introduction to python programming concepts
GautamDharamrajChouh
 
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
KosmikTech1
 
2. Getting Started with Python second lesson .pptx
Primary2Primary2
 
Ad

Recently uploaded (20)

PPTX
Inventory management chapter in automation and robotics.
atisht0104
 
PPTX
Civil Engineering Practices_BY Sh.JP Mishra 23.09.pptx
bineetmishra1990
 
PPT
Lecture in network security and mobile computing
AbdullahOmar704132
 
PDF
top-5-use-cases-for-splunk-security-analytics.pdf
yaghutialireza
 
PPTX
easa module 3 funtamental electronics.pptx
tryanothert7
 
PPT
Ppt for engineering students application on field effect
lakshmi.ec
 
PPTX
22PCOAM21 Session 2 Understanding Data Source.pptx
Guru Nanak Technical Institutions
 
PPTX
database slide on modern techniques for optimizing database queries.pptx
aky52024
 
PDF
Activated Carbon for Water and Wastewater Treatment_ Integration of Adsorptio...
EmilianoRodriguezTll
 
PDF
오픈소스 LLM, vLLM으로 Production까지 (Instruct.KR Summer Meetup, 2025)
Hyogeun Oh
 
PDF
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
PDF
The Effect of Artifact Removal from EEG Signals on the Detection of Epileptic...
Partho Prosad
 
PDF
Queuing formulas to evaluate throughputs and servers
gptshubham
 
PDF
Principles of Food Science and Nutritions
Dr. Yogesh Kumar Kosariya
 
PDF
Top 10 read articles In Managing Information Technology.pdf
IJMIT JOURNAL
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PDF
Software Testing Tools - names and explanation
shruti533256
 
PDF
EVS+PRESENTATIONS EVS+PRESENTATIONS like
saiyedaqib429
 
PPT
SCOPE_~1- technology of green house and poyhouse
bala464780
 
PPTX
Information Retrieval and Extraction - Module 7
premSankar19
 
Inventory management chapter in automation and robotics.
atisht0104
 
Civil Engineering Practices_BY Sh.JP Mishra 23.09.pptx
bineetmishra1990
 
Lecture in network security and mobile computing
AbdullahOmar704132
 
top-5-use-cases-for-splunk-security-analytics.pdf
yaghutialireza
 
easa module 3 funtamental electronics.pptx
tryanothert7
 
Ppt for engineering students application on field effect
lakshmi.ec
 
22PCOAM21 Session 2 Understanding Data Source.pptx
Guru Nanak Technical Institutions
 
database slide on modern techniques for optimizing database queries.pptx
aky52024
 
Activated Carbon for Water and Wastewater Treatment_ Integration of Adsorptio...
EmilianoRodriguezTll
 
오픈소스 LLM, vLLM으로 Production까지 (Instruct.KR Summer Meetup, 2025)
Hyogeun Oh
 
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
The Effect of Artifact Removal from EEG Signals on the Detection of Epileptic...
Partho Prosad
 
Queuing formulas to evaluate throughputs and servers
gptshubham
 
Principles of Food Science and Nutritions
Dr. Yogesh Kumar Kosariya
 
Top 10 read articles In Managing Information Technology.pdf
IJMIT JOURNAL
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
Software Testing Tools - names and explanation
shruti533256
 
EVS+PRESENTATIONS EVS+PRESENTATIONS like
saiyedaqib429
 
SCOPE_~1- technology of green house and poyhouse
bala464780
 
Information Retrieval and Extraction - Module 7
premSankar19
 
Ad

Chapter 1-Introduction and syntax of python programming.pptx

  • 1. 1 CHAPTER 1 Introduction and Syntax of Python programming
  • 2. 2 Features of Python • Simple • Easy to Learn • Versatile • Free and Open Source • High-level Language • Interactive • Portable • Object Oriented • Interpreted • Dynamic • Extensible • Embeddable • Extensive • Easy maintenance • Secure • Robust • Multi-threaded • Garbage Collection
  • 3. Applications of Python 3 • Embedded scripting language: Python is used as an embedded scripting language for various testing/ building/ deployment/ monitoring frameworks, scientific apps, and quick scripts. • 3D Software: 3D software like Maya uses Python for automating small user tasks, or for doing more complex integration such as talking to databases and asset management systems. • Web development: Python is an easily extensible language that provides good integration with database and other web standards. GUI-based desktop applications: Simple syntax, modular architecture, rich text processing tools and the ability to work on multiple operating systems makes Python a preferred choice for developing desktop- based applications. • Image processing and graphic design applications: Python is used to make 2D imaging software such as Inkscape, GIMP, Paint Shop Pro and Scribus. It is also used to make 3D animation packages, like Blender, 3ds Max, Cinema 4D, Houdini, Lightwave and Maya.
  • 4. 4 Applications of Python • Scientific and computational applications: Features like high speed, productivity and availability of tools, such as Scientific Python and Numeric Python, have made Python a preferred language to perform computation and processing of scientific data. 3D modeling software, such as FreeCAD, and finite element method software, like Abaqus, are coded in Python. Games: Python has various modules, libraries, and platforms that support development of games. Games like Civilization-IV, Disney'sToontown Online,Vega Strike, etc. are coded using Python. • Enterprise and business applications: Simple and reliable syntax, modules and libraries, extensibility, scalability together make Python a suitable coding language for customizing larger applications. For example, Reddit which was originally written in Common Lips, was rewritten in Python in 2005. A large part of Youtube code is also written in Python. • Operating Systems: Python forms an integral part of Linux distributions.
  • 5. 5 Writing and Executing First Python Program Step 1: Open an editor. Step 2: Write the instructions Step 3: Save it as a file with the filename having the extension .py. Step 4: Run the interpreter with the command python program_name.py or use IDLE to run the programs. To execute the program at the command prompt, simply change your working directory to C:Python34 (or move to the directory where you have saved Python) then type python program_name.py. If you want to execute the program in Python shell, then just press F5 key or click on Run Menu and then select Run Module.
  • 6. 6 Types of mode: A. Interactive mode B. Script Mode A. Interactive Mode: In the interactive mode as we enter a command and press enter, the very next step we get the output. The output of the code in the interactive mode is influenced by the last command we give. Interactive mode is very convenient for writing very short lines of code. print(“Hello”) Disadvantages of Interactive mode: • The interactive mode is not suitable for large programs. • The interactive mode doesn’t save the statements. Once we make a program it is for that time itself, we cannot use it in the future. In order to use it in the future, we need to retype all the statements. • Editing the code written in interactive mode is a tedious task.We need to revisit all our previous commands and if still, we could not edit we need to type everything again. Modes in Python
  • 7. 7 B. Script Mode: In the script mode, a python program can be written in a file.This file can then be saved and executed using the command prompt.We can view the code at any time by opening the file and editing becomes quite easy as we can open and view the entire code as many times as we want.
  • 8. 8
  • 9. 9 Literal Constants The value of a literal constant can be used directly in programs. For example, 7, 3.9, 'A', and "Hello" are literal constants. Numbers refers to a numeric value.You can use four types of numbers in Python program- integers, long integers, floating point and complex numbers. • Numbers like 5 or other whole numbers are referred to as integers. Bigger whole numbers are called long integers. For example, 535633629843L is a long integer. • Numbers like are 3.23 and 91.5E-2 are termed as floating point numbers. • Numbers of a + bi form (like -3 + 7i) are complex numbers. Examples:
  • 10. 10 Literal Constants Strings A string is a group of characters. • Using Single Quotes ('): For example, a string can be written as 'HELLO'. • Using Double Quotes ("): Strings in double quotes are exactly same as those in single quotes.Therefore, 'HELLO' is same as "HELLO". • UsingTriple Quotes (''' '''): You can specify multi-line strings using triple quotes.You can use as many single quotes and double quotes as you want in a string within triple quotes. Examples:
  • 11. 11 print("Welcome to Python Programming Language") print('Welcome to Python Programming Language') print('''Welcome to Python Programming Language''')
  • 12. 12 Escape Sequences Some characters (like ", ) cannot be directly included in a string. Such characters must be escaped by placing a backslash before them. Example:
  • 13. 13 Raw Strings If you want to specify a string that should not handle any escape sequences and want to display exactly as specified then you need to specify that string as a raw string. A raw string is specified by prefixing r or R to the string. Example:
  • 15. 15 Variables and Identifiers Variable means its value can vary. You can store any piece of information in a variable. Variables are nothing but just parts of your computer’s memory where information is stored.To be identified easily, each variable is given an appropriate name. Identifiers are names given to identify something. This something can be a variable, function, class, module or other object. For naming any identifier, there are some basic rules like: • The first character of an identifier must be an underscore ('_') or a letter (upper or lowercase). • The rest of the identifier name can be underscores ('_'), letters (upper or lowercase), or digits (0-9). • Identifier names are case-sensitive. For example, myvar and myVar are not the same. • Punctuation characters such as @, $, and % are not allowed within identifiers. Examples of valid identifier names are sum, __my_var, num1, r, var_20, First, etc. Examples of invalid identifier names are 1num, my-var, %check, Basic Sal, H#R&A, etc.
  • 16. 16 Assigning or InitializingValues toVariables In Python, programmers need not explicitly declare variables to reserve memory space.The declaration is done automatically when a value is assigned to the variable using the equal sign (=).The operand on the left side of equal sign is the name of the variable and the operand on its right side is the value to be stored in that variable. Example:
  • 17. 17 s="Python" a=100 b=10.5 c=5+3j print("sting="+s) print("int number="+str(a)) print("float number="+str(b)) print("complex number="+str(c)) print("nn") a,b,c=100,10.5,5+3j print("sting="+s) print("int number="+str(a)) print("float number="+str(b)) print("complex number="+str(c)) print("nn") a=b=c=0 print(a) print(b) print(c)
  • 18. 18 Comments Comments are the non-executable statements in a program. They are just added to describe the statements in the program code. Comments make the program easily readable and understandable by the programmer as well as other users who are seeing the code. The interpreter simply ignores the comments.
  • 19. 19 1. Single Line Comments: In Python for single line comments use # sign to comment out everything following it on that line. 2. Multiple Lines Comments: Multiple lines comments are slightly different. Simply use 3 single quotes before and after the part you want to be commented. Example: #This is comment #print("Statement will not be executed") print("Statement will be excuted") '''print("Multiple line comment") print("Multiple line comment") print("Multiple line comment")'''
  • 20. 20 Input Operation To take input from the users, Python makes use of the input() function.The input() function prompts the user to provide some information on which the program can work and give the result. However, we must always remember that the input function takes user’s input as a string. Example:
  • 21. 21 a=input("Enter a number") b=input("Enter a number") print(a+b) a=int(input("Enter a number")) b=int(input("Enter a number")) print(a+b)
  • 22. 22 a=float(input("Enter a number")) b=float(input("Enter a number")) print(a+b) a=complex(input("Enter a number")) b=complex(input("Enter a number")) print(a+b)
  • 23. 23 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 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: DataType
  • 24. 24 x = str("Hello World") str x = int(20) int x = float(20.5) float x = complex(1j) complex x = list(("apple", "banana", "cherry")) list x = tuple(("apple", "banana", "cherry")) tuple x = range(6) range x = dict(name="John", age=36) dict x = set(("apple", "banana", "cherry")) set x = frozenset(("apple", "banana", "cherry")) frozenset x = bool(5) bool Examples:
  • 25. 25 x = bytes(5) bytes x = bytearray(5) bytearray x = memoryview(bytes(5)) memoryview
  • 26. 26 Boolean Values -In programming you often need to know if an expression is True or False. -You can evaluate any expression in Python, and get one of two answers, True or False. -When you compare two values, the expression is evaluated and Python returns the Boolean answer: print(10 > 9) print(10 == 9) print(10 < 9)