[Reading] AfterWork_ Python Programming Basics
[Reading] AfterWork_ Python Programming Basics
Learning Outcomes
By the end of this session, you will have covered the following learning outcomes:
● I can use the print() function to display the output of a python program.
● I can create variables to store data in a python program.
● I can write comments to provide explanations of how code works.
● I can write arithmetic operators to perform mathematical operations.
● I can determine the data types of different types of data.
● I can use lists, dictionaries, and sets to store data.
● I can use conditional (if) statements to check for conditions in data.
● I can use for loops and while loops to iterate through data.
● I can create functions, classes, and objects to write reusable code.
Overview
The Python programming language is one of the most popular programming languages in
Data Science. A comparison from a Kaggle survey [ Link] of several programming languages
used in data science shows that the programming language continues to grow in popularity due
to ease of use, vast developer community, and appropriate data science libraries.
By the end of this session, you will be able to demonstrate the use of crucial python
programming concepts such as printing, variables, comments, arithmetic operators, data types,
lists, conditional (if) statements, dictionaries, sets, for loops, while loops, functions, classes, and
objects.
Terminology
● Comments are used in our code to provide explanatory information about the code.
● Variables - These are names that we give to computer memory locations used to
store values in a computer program.
● Arithmetic Operators - These are mathematical functions that take two values and
perform a calculation on them.
● Data types - A data type is a classification that specifies which type of value a
variable contains.
● Lists - A list is a compound data type that allows for storing items of different data
types.
● Conditional (if) Statements - We use conditional-if statements to make decisions.
For example, to run code only when statements are true.
Main Resources
Reading
Printing
● print() is one of the most popular python commands.
● This command print means "show on the screen".
Variables
● Variables are storage containers for data.
● For example, a food variable could contain "Spaghetti" or "Rice" or any other
value.
● The value of a variable can change depending on conditions or information
passed to the program.
● Variable names must begin with a letter, underscore, or non-number character.
Each programming language has its naming conventions to guide how variables
are named.
● Every programming language has reserved words. We can’t use these words as
variable names, for example, Date. Instead, we might name your date-related
variables dte or StartDate.
● Once we create variables, we are then able to perform operations taking into
account the stored values.
Comments
● We use comments to explain how a program works.
● Comments don’t have any effect on your program.
● Comments have the following goals:
○ To explain what a particular code does.
○ To explain something which might not be evident to the reader.
○ To clarify your intention behind a particular line or block of code.
○ To serve as a reminder to change something in the future.
Arithmetic Operators
● Arithmetic operators perform mathematical operations such as addition,
subtraction, multiplication, division, modulus, exponentiation, etc.
Functions
● A function is a block of organized, reusable code.
● A common usage of functions is to implement mathematical functions.
● As we will get to see, a function block begins with the keyword def followed by
the function name and parentheses ().
Further Resources
● Python Basics for Data Science. [Link]
● Python Documentation. [Link]