SlideShare a Scribd company logo
4
Most read
6
Most read
7
Most read
http://www.skillbrew.com
/SkillbrewTalent brewed by the
industry itself
Statements, Code Blocks and Indentation
Pavan Verma
Python Programming Essentials
1
@YinYangPavan
© SkillBrew http://skillbrew.com
Python statements
 A statement is a one Python instruction
 Most of the time, there is exactly one Python
statement per line
>>> x = 4 + 6
>>> y = x**2
>>> print y
100
2
© SkillBrew http://skillbrew.com
Multiple statements on one line
 It’s possible to have multiple statements,
separated by semi-colon, on a single line
 Doing so is NOT recommended as it reduces
code readability
>>> x = 4 + 6; y = x**2; print y
100
3
© SkillBrew http://skillbrew.com
Statements can span multiple lines
 There are two ways to make a statement span
multiple lines
 Use it if it improves code readability by
breaking a very long statement
4
>>> x = 4 + 
6
>>> x
10
>>> x = (4
+
6)
>>> x
10
© SkillBrew http://skillbrew.com
Code blocks
 A code block is a set of statements that will be
executed together, one after the other
 if statements, for loops, while loops, functions, are all
code blocks
if x > 10:
is_greater = True
print "Greater than 10"
else:
is_greater = False
print "Not greater than 10"
5
© SkillBrew http://skillbrew.com
Code blocks and Indentation
 Code blocks have no explicit begin or end. There
are no explicit braces, brackets, or keywords.
 Code blocks are defined by their indentation
• Indenting starts a block and unindenting ends it
• The only delimiter is a colon (:) and the indentation
of the code itself
 This means that whitespace is significant, and
must be consistent
6
© SkillBrew http://skillbrew.com
Sample code blocks
def fib(n):
print 'n = ', n
if n > 1:
return n * fib(n-1)
else:
print 'end'
return 1
7
© SkillBrew http://skillbrew.com
Sample code blocks (2)
8
def fib(n):
print 'n = ', n
if n > 1:
return n * fib(n-1)
else:
print 'end'
return 1
© SkillBrew http://skillbrew.com
Sample code blocks (3)
9
def fib(n):
print 'n = ', n
if n > 1:
return n * fib(n-1)
else:
print 'end'
return 1
© SkillBrew http://skillbrew.com
Sample code blocks (4)
10
def fib(n):
print 'n = ', n
if n > 1:
return n * fib(n-1)
else:
print 'end'
return 1
© SkillBrew http://skillbrew.com
Indentation Tips
 Use 4 spaces per indentation level
 Spaces are the preferred indentation method
 Use spaces for indentation; not tabs
• 1 tab == 1 indent level
 Python 3 explicitly disallows mixing the use of
tabs and spaces for indentation
11
© SkillBrew http://skillbrew.com
Summary
 Statements
 Relationship between Python statements
and lines
 Code blocks
 Relationship between code blocks and
indentation in Python
12
13

More Related Content

PPT
Unit 3-pipelining & vector processing
PPTX
Threaded Binary Tree
PPTX
Dynamic memory allocation in c++
PPT
Virtual memory
PPTX
Operating system memory management
PPTX
Virtual memory presentation
PPT
Memory Management in OS
PPT
Parallel processing
Unit 3-pipelining & vector processing
Threaded Binary Tree
Dynamic memory allocation in c++
Virtual memory
Operating system memory management
Virtual memory presentation
Memory Management in OS
Parallel processing

What's hot (20)

PDF
Python-01| Fundamentals
PPTX
Strings in C
PPT
Ram & rom memories
PPT
Files concepts.53
PPTX
Main Memory
PDF
Process & Thread Management
PPTX
Python - Numpy/Pandas/Matplot Machine Learning Libraries
PPTX
Operating system 25 classical problems of synchronization
PPT
Services provided by os
ODP
Introduction to Shell script
PPT
File handling in c
PPT
Deadlock detection and recovery by saad symbian
PPT
Arrays in c
PPT
Operation on string presentation
PPTX
File Management in Operating System
PPTX
Function in C program
PPTX
Process , Process states , Process Control Block in Operating Systems
PPTX
Memory management ppt
PPTX
Memory technology and optimization in Advance Computer Architechture
PPT
Multicore Processors
Python-01| Fundamentals
Strings in C
Ram & rom memories
Files concepts.53
Main Memory
Process & Thread Management
Python - Numpy/Pandas/Matplot Machine Learning Libraries
Operating system 25 classical problems of synchronization
Services provided by os
Introduction to Shell script
File handling in c
Deadlock detection and recovery by saad symbian
Arrays in c
Operation on string presentation
File Management in Operating System
Function in C program
Process , Process states , Process Control Block in Operating Systems
Memory management ppt
Memory technology and optimization in Advance Computer Architechture
Multicore Processors
Ad

Viewers also liked (20)

PDF
Python tutorial
PDF
Python - basics
PDF
PythonIntro
PDF
Python Tutorial
PDF
AmI 2015 - Python basics
PDF
Python Basics
PDF
python codes
PDF
Python Workshop
PPTX
Python basics
PPTX
Introduction to the basics of Python programming (part 1)
PDF
AmI 2016 - Python basics
PDF
Introduction to python programming
PPTX
PPT
Classification of computers
PDF
Introduction to python 3 2nd round
PPTX
Evolution and classification of computers
PPTX
Python programming language
DOCX
Classification of computers
PPTX
Introduction to Python Basics Programming
PPTX
Python 101
Python tutorial
Python - basics
PythonIntro
Python Tutorial
AmI 2015 - Python basics
Python Basics
python codes
Python Workshop
Python basics
Introduction to the basics of Python programming (part 1)
AmI 2016 - Python basics
Introduction to python programming
Classification of computers
Introduction to python 3 2nd round
Evolution and classification of computers
Python programming language
Classification of computers
Introduction to Python Basics Programming
Python 101
Ad

Similar to Python Programming Essentials - M6 - Code Blocks and Indentation (20)

PPTX
Python Programming Essentials - M31 - PEP 8
PPTX
Python Programming Essentials - M7 - Strings
PDF
New features in Ruby 2.5
PPTX
Top Python Best Practices To Boost Code Efficiency
PDF
Functional Smalltalk
DOCX
Cmis 102 Enthusiastic Study / snaptutorial.com
DOCX
Cmis 102 Success Begins / snaptutorial.com
DOCX
Cmis 102 Effective Communication / snaptutorial.com
PDF
Optimization in Programming languages
PPTX
Code Practices
PDF
100 bugs in Open Source C/C++ projects
PDF
lab-assgn-practical-file-xii-cs.pdf
DOCX
CMIS 102 Entire Course NEW
PDF
The Hitchhiker's Guide to Faster Builds. Viktor Kirilov. CoreHard Spring 2019
PPTX
Improving Code Quality Through Effective Review Process
PDF
100 bugs in Open Source C/C++ projects
PPTX
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
PPTX
08 - Return Oriented Programming, the chosen one
PPT
My programming final proj. (1)
PPTX
C++ Core Guidelines
Python Programming Essentials - M31 - PEP 8
Python Programming Essentials - M7 - Strings
New features in Ruby 2.5
Top Python Best Practices To Boost Code Efficiency
Functional Smalltalk
Cmis 102 Enthusiastic Study / snaptutorial.com
Cmis 102 Success Begins / snaptutorial.com
Cmis 102 Effective Communication / snaptutorial.com
Optimization in Programming languages
Code Practices
100 bugs in Open Source C/C++ projects
lab-assgn-practical-file-xii-cs.pdf
CMIS 102 Entire Course NEW
The Hitchhiker's Guide to Faster Builds. Viktor Kirilov. CoreHard Spring 2019
Improving Code Quality Through Effective Review Process
100 bugs in Open Source C/C++ projects
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
08 - Return Oriented Programming, the chosen one
My programming final proj. (1)
C++ Core Guidelines

More from P3 InfoTech Solutions Pvt. Ltd. (20)

PPTX
Python Programming Essentials - M44 - Overview of Web Development
PPTX
Python Programming Essentials - M40 - Invoking External Programs
PPTX
Python Programming Essentials - M39 - Unit Testing
PPTX
Python Programming Essentials - M37 - Brief Overview of Misc Concepts
PPTX
Python Programming Essentials - M35 - Iterators & Generators
PPTX
Python Programming Essentials - M34 - List Comprehensions
PPTX
Python Programming Essentials - M29 - Python Interpreter and Files
PPTX
Python Programming Essentials - M28 - Debugging with pdb
PPTX
Python Programming Essentials - M27 - Logging module
PPTX
Python Programming Essentials - M25 - os and sys modules
PPTX
Python Programming Essentials - M24 - math module
PPTX
Python Programming Essentials - M23 - datetime module
PPTX
Python Programming Essentials - M22 - File Operations
PPTX
Python Programming Essentials - M21 - Exception Handling
PPTX
Python Programming Essentials - M20 - Classes and Objects
PPTX
Python Programming Essentials - M19 - Namespaces, Global Variables and Docstr...
PPTX
Python Programming Essentials - M18 - Modules and Packages
PPTX
Python Programming Essentials - M17 - Functions
PPTX
Python Programming Essentials - M16 - Control Flow Statements and Loops
PPTX
Python Programming Essentials - M15 - References
Python Programming Essentials - M44 - Overview of Web Development
Python Programming Essentials - M40 - Invoking External Programs
Python Programming Essentials - M39 - Unit Testing
Python Programming Essentials - M37 - Brief Overview of Misc Concepts
Python Programming Essentials - M35 - Iterators & Generators
Python Programming Essentials - M34 - List Comprehensions
Python Programming Essentials - M29 - Python Interpreter and Files
Python Programming Essentials - M28 - Debugging with pdb
Python Programming Essentials - M27 - Logging module
Python Programming Essentials - M25 - os and sys modules
Python Programming Essentials - M24 - math module
Python Programming Essentials - M23 - datetime module
Python Programming Essentials - M22 - File Operations
Python Programming Essentials - M21 - Exception Handling
Python Programming Essentials - M20 - Classes and Objects
Python Programming Essentials - M19 - Namespaces, Global Variables and Docstr...
Python Programming Essentials - M18 - Modules and Packages
Python Programming Essentials - M17 - Functions
Python Programming Essentials - M16 - Control Flow Statements and Loops
Python Programming Essentials - M15 - References

Recently uploaded (20)

PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
PDF
Sensors and Actuators in IoT Systems using pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
CroxyProxy Instagram Access id login.pptx
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Omni-Path Integration Expertise Offered by Nor-Tech
PDF
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
PDF
REPORT: Heating appliances market in Poland 2024
PPTX
MYSQL Presentation for SQL database connectivity
PDF
KodekX | Application Modernization Development
PDF
Advanced IT Governance
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Newfamily of error-correcting codes based on genetic algorithms
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PPTX
Cloud computing and distributed systems.
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
Sensors and Actuators in IoT Systems using pdf
NewMind AI Weekly Chronicles - August'25 Week I
CroxyProxy Instagram Access id login.pptx
NewMind AI Monthly Chronicles - July 2025
Omni-Path Integration Expertise Offered by Nor-Tech
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
REPORT: Heating appliances market in Poland 2024
MYSQL Presentation for SQL database connectivity
KodekX | Application Modernization Development
Advanced IT Governance
Review of recent advances in non-invasive hemoglobin estimation
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Newfamily of error-correcting codes based on genetic algorithms
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
GamePlan Trading System Review: Professional Trader's Honest Take
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
Cloud computing and distributed systems.

Python Programming Essentials - M6 - Code Blocks and Indentation