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

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

PPT
notwa dfdfvs gf fdgfgh s thgfgh frg reggg
Godwin585235
 
PPT
Py-Slides-1.pptPy-Slides-1.pptPy-Slides-1.pptPy-Slides-1.ppt
v65176016
 
PPTX
Python fundamentals
natnaelmamuye
 
PDF
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
KosmikTech1
 
PPTX
Pyhton problem solving introduction and examples
ssuser65733f
 
PDF
Python Programing Bio computing,basic concepts lab,,
smohana4
 
PDF
Fundamentals of python
BijuAugustian
 
PDF
problem solving and python programming UNIT 2.pdf
rajesht522501
 
PDF
Problem Solving and Python Programming UNIT 2.pdf
rajesht522501
 
PPTX
python questionsfor class 8 students and
RameshKumarYadav29
 
PPTX
Python unit 2 is added. Has python related programming content
swarna16
 
PPTX
python notes for MASTER OF COMPUTER APPLIICATION_ppt.pptx
yuvarajkumar334
 
PPTX
Introduction to Python Programming .pptx
NaynaSagarDahatonde
 
PDF
Python-01| Fundamentals
Mohd Sajjad
 
PPTX
Python Fundamentals for the begginers in programming
bsse20142018
 
PPTX
Lecture1_introduction to python.pptx
MohammedAlYemeni1
 
PDF
How To Tame Python
Mohd Anwar Jamal Faiz
 
PDF
GE3151_PSPP_UNIT_2_Notes
Guru Nanak Technical Institutions
 
PPTX
Python PPT.pptx
JosephMuez2
 
DOCX
INTERNSHIP REPORT.docx
21IT200KishorekumarI
 
notwa dfdfvs gf fdgfgh s thgfgh frg reggg
Godwin585235
 
Py-Slides-1.pptPy-Slides-1.pptPy-Slides-1.pptPy-Slides-1.ppt
v65176016
 
Python fundamentals
natnaelmamuye
 
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
KosmikTech1
 
Pyhton problem solving introduction and examples
ssuser65733f
 
Python Programing Bio computing,basic concepts lab,,
smohana4
 
Fundamentals of python
BijuAugustian
 
problem solving and python programming UNIT 2.pdf
rajesht522501
 
Problem Solving and Python Programming UNIT 2.pdf
rajesht522501
 
python questionsfor class 8 students and
RameshKumarYadav29
 
Python unit 2 is added. Has python related programming content
swarna16
 
python notes for MASTER OF COMPUTER APPLIICATION_ppt.pptx
yuvarajkumar334
 
Introduction to Python Programming .pptx
NaynaSagarDahatonde
 
Python-01| Fundamentals
Mohd Sajjad
 
Python Fundamentals for the begginers in programming
bsse20142018
 
Lecture1_introduction to python.pptx
MohammedAlYemeni1
 
How To Tame Python
Mohd Anwar Jamal Faiz
 
GE3151_PSPP_UNIT_2_Notes
Guru Nanak Technical Institutions
 
Python PPT.pptx
JosephMuez2
 
INTERNSHIP REPORT.docx
21IT200KishorekumarI
 

Recently uploaded (20)

PDF
Bachelor of information technology syll
SudarsanAssistantPro
 
PPTX
DATA BASE MANAGEMENT AND RELATIONAL DATA
gomathisankariv2
 
PDF
mbse_An_Introduction_to_Arcadia_20150115.pdf
henriqueltorres1
 
PPTX
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
PDF
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
PPTX
Biosensors, BioDevices, Biomediccal.pptx
AsimovRiyaz
 
PDF
Data structures notes for unit 2 in computer science.pdf
sshubhamsingh265
 
PPTX
澳洲电子毕业证澳大利亚圣母大学水印成绩单UNDA学生证网上可查学历
Taqyea
 
PPTX
Knowledge Representation : Semantic Networks
Amity University, Patna
 
PPTX
How Industrial Project Management Differs From Construction.pptx
jamespit799
 
PPTX
原版一样(EC Lille毕业证书)法国里尔中央理工学院毕业证补办
Taqyea
 
PPT
Testing and final inspection of a solar PV system
MuhammadSanni2
 
PDF
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
PDF
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
PPTX
Worm gear strength and wear calculation as per standard VB Bhandari Databook.
shahveer210504
 
PDF
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
PDF
NTPC PATRATU Summer internship report.pdf
hemant03701
 
PPTX
Distribution reservoir and service storage pptx
dhanashree78
 
PDF
WD2(I)-RFQ-GW-1415_ Shifting and Filling of Sand in the Pond at the WD5 Area_...
ShahadathHossain23
 
PDF
AN EMPIRICAL STUDY ON THE USAGE OF SOCIAL MEDIA IN GERMAN B2C-ONLINE STORES
ijait
 
Bachelor of information technology syll
SudarsanAssistantPro
 
DATA BASE MANAGEMENT AND RELATIONAL DATA
gomathisankariv2
 
mbse_An_Introduction_to_Arcadia_20150115.pdf
henriqueltorres1
 
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
Biosensors, BioDevices, Biomediccal.pptx
AsimovRiyaz
 
Data structures notes for unit 2 in computer science.pdf
sshubhamsingh265
 
澳洲电子毕业证澳大利亚圣母大学水印成绩单UNDA学生证网上可查学历
Taqyea
 
Knowledge Representation : Semantic Networks
Amity University, Patna
 
How Industrial Project Management Differs From Construction.pptx
jamespit799
 
原版一样(EC Lille毕业证书)法国里尔中央理工学院毕业证补办
Taqyea
 
Testing and final inspection of a solar PV system
MuhammadSanni2
 
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
Worm gear strength and wear calculation as per standard VB Bhandari Databook.
shahveer210504
 
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
NTPC PATRATU Summer internship report.pdf
hemant03701
 
Distribution reservoir and service storage pptx
dhanashree78
 
WD2(I)-RFQ-GW-1415_ Shifting and Filling of Sand in the Pond at the WD5 Area_...
ShahadathHossain23
 
AN EMPIRICAL STUDY ON THE USAGE OF SOCIAL MEDIA IN GERMAN B2C-ONLINE STORES
ijait
 
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)