Opportunity Through Data Textbook
  • Opportunity Through Data Textbook
  • Introduction
    • What is Data Science?
    • Introduction to Data Science: Exploratory Musical Analysis
  • Module 1
    • Introduction to Programming
      • The Command Line
      • Installing Programs
      • Python and the Command Line
      • Jupyter Notebook
    • Introduction to Python
      • Building Blocks of Python - Data Types and Variables
      • Functions
      • Formatting and Syntax
    • Math Review
      • Variables and Functions
      • Intro to Graphs
  • Module 2
    • Data Structures
      • Lists
      • Dictionaries
      • Tables
    • Programming Logic
      • Loops
      • Logical Operators
      • Conditionality
  • Module 3
    • Introduction to Probability
      • Probability and Sampling
    • Introduction to Statistics
      • Mean & Variance
      • Causality & Randomness
  • Module 4
    • Packages
    • Intro to NumPy
      • NumPy (continued)
  • Module 5
    • Introduction to Pandas
      • Introduction to Dataframes
      • Groupby and Join
    • Working with Data
    • Data Visualization
      • Matplotlib
      • Introduction to Data Visualization
  • Appendix
    • Table Utilities
    • Area of More Complicated Shapes
    • Introduction to Counting
    • Slope and Distance
    • Short Circuiting
    • Linear Regression
    • Glossary
  • Extension: Classification
    • Classification
    • Test Sets and Training Sets
    • Nearest Neighbors
  • Extension: Introduction to SQL
    • Introduction to SQL
    • Table Operations
      • Tables and Queries
      • Joins
  • Extension: Central Limit Theorem
    • Overview
    • Probability Distributions
      • Bernoulli Distribution
      • Uniform Distribution (Discrete)
      • Random Variables, Expectation, Variance
      • Discrete and Continuous Distributions
      • Uniform Distribution (Continuous)
      • Normal Distribution
    • Central Limit Theorem in Action
    • Confidence Intervals
  • Extension: Object-Oriented Programming
    • Object-Oriented Programming
      • Classes
      • Instantiation
      • Dot Notation
      • Mutability
  • Extension: Introduction to Excel
    • Introduction to Excel
      • Terminology and Interface
      • Getting Started with Analysis and Charts
      • Basics of Manipulating Data
    • Additional Features in Excel
      • Macros
      • The Data Tab
      • Pivot Tables
Powered by GitBook
On this page
  • Python Indentation
  • Comments

Was this helpful?

  1. Module 1
  2. Introduction to Python

Formatting and Syntax

Python Indentation

Python uses indentation to define a block of code. Indentation means that there is a space at the beginning of the line - similar to the space at the beginning of a paragraph in English. In python, you can make a single level indent by either using four spaces or the tab key once. An example is show below:

if 1==1: 
#### 4 spaces or 1 tab spot
    print("This is indent level 1")
    if 2==2:
######## 8 spaces or 2 tab spots
        print("This is indent level 2")

Comments

#This is a comment. 

You might have seen statements starting with '#' such as the one above in our code. These statements are called comments. To write a comment in Python, just make sure to start your statement with a hashtag like in the example above.

Comments can be used whenever you feel there is a need to explain your code or certain steps you take to approach a problem in your program. We recommend using comments to keep track of your code, because in some instances you might come back to it after a month and not remember what your code does. Comments can be especially useful when other people look at your code so that they do not have to decipher an entire code block to know what it does.

PreviousFunctionsNextMath Review

Last updated 5 years ago

Was this helpful?