📕
Dan Fitz's Notes
  • README
  • Ai
    • Supervised Machine Learning
      • Introduction To Machine Learning
      • Regression With Multiple Input Variables
      • Classification
  • Csharp
    • C Sharp Advanced
      • Generics
      • Delegates
      • Lambda Expressions
      • Events
    • C Sharp Fundamentals
      • Intro To C
      • Primitive Types And Expressions
      • Non Primitive Types
      • Control Flow
      • Arrays And Lists
      • Working With Dates
      • Working With Text
      • Working With Files
      • Debugging Applications
    • C Sharp Intermediate
      • Classes
      • Association Between Classes
      • Inheritance
      • Polymorphism
      • Interfaces
  • Java
    • Inheritance Data Structures Java
      • Inheritance Polymorphism Using Overriding And Access Modifiers
      • Abstract Classes And Debugging
      • File I O And Exceptions
      • Collections Maps And Regular Expressions
    • Intro To Java
      • Introduction To Java Classes And Eclipse
      • Unit Testing Arrays And Array Lists
      • Static Variables Methods And Polymorphism Using Overloading
  • Javascript
    • Algorithms Data Structures
      • Big O Notation
      • Analyzing Performance Of Arrays And Objects
      • Problem Solving Approach
      • Problem Solving Patterns
      • Recursion
      • Searching Algorithms
      • Bubble Selection And Insertion Sort
      • Merge Sort
      • Quick Sort
      • Radix Sort
      • Data Structures Introduction
      • Singly Linked Lists
      • Doubly Linked Lists
      • Stacks And Queues
      • Binary Search Trees
      • Tree Traversal
      • Binary Heaps
    • Complete Nodejs
      • Understanding Node.js
      • REST AP Is And Mongoose
      • API Authentication And Security
      • Node.js Module System
      • File System And Command Line Args
      • Debugging Node.js
      • Asynchronous Node.js
      • Web Servers
      • Accessing API From Browser
      • Application Deployment
      • Mongo DB And Promises
    • Complete React Native
      • Working With Content
      • Building Lists
      • Navigating Users Between Screens
      • State Management
      • Handling Screen Layout
      • Setting Up An App
      • More On Navigation
      • Advanced Statement Management With Context
      • Building A Custom Express API
      • In App Authentication
    • Epic React
      • React Fundamentals
      • React Hooks
      • Advanced React Hooks
      • Advanced React Patterns
      • React Performance
    • Fireship Firestore
      • Firestore Queries And Data Modeling Course
      • Model Relational Data In Firestore No SQL
    • Functional Light Javascript
      • Intro
      • Function Purity
      • Argument Adapters
      • Point Free
      • Closure
      • Composition
      • Immutability
      • Recursion
      • List Operations
      • Transduction
      • Data Structure Operations
      • Async
    • Js Weird Parts
      • Execution Contexts And Lexical Environments
      • Types And Operators
      • Objects And Functions
      • Object Oriented Java Script And Prototypal Inheritance
      • Defining Objects
    • Mastering Chrome Dev Tools
      • Introduction
      • Editing
      • Debugging
      • Networking
      • Auditing
      • Node.js Profiling
      • Performance Monitoring
      • Image Performance
      • Memory
    • React Complete Guide
      • What Is React
      • React Basics
      • Rendering Lists And Conditionals
      • Styling React Components
      • Debugging React Apps
      • Component Deep Dive
      • Building A React App
      • Reaching Out To The Web
      • Routing
    • React Testing
      • Intro To Jest Enzyme And TDD
      • Basic Testing
      • Redux Testing
      • Redux Thunk Testing
    • Serverless Bootcamp
      • Introduction
      • Auction Service Setup
      • Auction Service CRUD Operations
      • Auction Service Processing Auctions
    • Testing Javascript
      • Fundamentals Of Testing
      • Static Analysis Testing
      • Mocking Fundamentals
      • Configuring Jest
      • Test React Components With Jest And React Testing Library
    • Typescript Developers Guide
      • Getting Started With Type Script
      • What Is A Type System
      • Type Annotations In Action
      • Annotations With Functions And Objects
      • Mastering Typed Arrays
      • Tuples In Type Script
      • The All Important Interface
      • Building Functionality With Classes
    • Web Performance With Webpack
      • Intro
      • Code Splitting
      • Module Methods Magic Comments
  • Other
    • Algo Expert
      • Defining Data Structures And Complexity Analysis
      • Memory
      • Big O Notation
      • Logarithm
      • Arrays
      • Linked Lists
      • Hash Tables
      • Stacks And Queues
      • Strings
      • Graphs
      • Trees
    • Aws Solutions Architect
      • AWS Fundamentals IAM EC 2
    • Fundamentals Math
      • Numbers And Negative Numbers
      • Factors And Multiples
      • Fractions
    • Mysql Bootcamp
      • Overview And Installation
      • Creating Databases And Tables
      • Inserting Data
      • CRUD Commands
      • The World Of String Functions
      • Refining Our Selections
      • The Magic Of Aggregate Functions
    • Random Notes
      • Understanding React Hooks
  • Python
    • Data Analysis Using Python
      • Loading Querying And Filtering Data Using The Csv Module
      • Loading Querying Joining And Filtering Data Using Pandas
      • Summarizing And Visualizing Data
    • Intro To Python
      • Course Introduction Intro To Programming And The Python Language Variables Conditionals Jupyter Notebook And IDLE
      • Intro To Lists Loops And Functions
      • More With Lists Strings Tuples Sets And Py Charm
      • Dictionaries And Files
Powered by GitBook
On this page
  • Print command
  • Basic data types
  • Arithmetic operators
  • Booleans
  • Strings
  • Casting
  • Python scripts
  • Variables
  • Control flow
  • Checking errors
  1. Python
  2. Intro To Python

Course Introduction Intro To Programming And The Python Language Variables Conditionals Jupyter Notebook And IDLE

Characteristics of Python:

  • High-level language (i.e., more abstracted from lower-level details of the computer)

  • OOP language

  • Interpreted language (i.e., does not need to be compiled from one language to another)

    • One side effect of being interpreted is that the lack of compilation to another language can mean less automatic error checking, so more onus on you to ensure code is bug-free

  • Open source

Common use cases of Python:

  • AI (e.g., NLP or machine learning)

  • Web dev

  • Data analysis & visualization

  • Desktop GUIs

  • Game dev

Print command

print has a few useful arguments called end and sep.

end allows you to specify how the string should end when printed (default is ):

print('Hello,', end = ' ')
print('Dan')
# Prints "Hello, Dan"

sep defines if there is a character between string arguments (default is empty string or single space):

print('Hello', 'Dan', sep = ', ')
# Prints "Hello, Dan"

Basic data types

  • int is a mathematical integer

  • float is a number with a decimal point

Note: The type function can very quickly tell you what data type a value is.

Arithmetic operators

Operators are the same with a few unique exceptions:

  • Addition +

  • Subtraction -

  • Multiplication *

  • Division /

  • Integer division //

    • Returns the number of full divisions, discarding the fractional part of the result

  • Exponentiation **

  • Modulus %

Booleans

Boolean values are True and False.

Comparison operators are the same:

  • Equal ==

  • Not equal != <>

  • Less than and greater than < >

  • Less than or equal as well as greater than or equal <= >=

Boolean operators are:

  • and

  • or

  • not

Note: All objects can be casted to a boolean via the bool function.

Strings

When concatenating strings, Python requires that the inputs are all strings, so it doesn't automatically cast the values to strings for you.

# This doesn't work
"4 / 3 = " + (4 / 3)

Note: An alternative way of combining strings is using the str.format method. (See docs for more details.)

Casting

Here are some useful casting functions to convert data types into other data types:

  • bool

  • int

  • str

Python scripts

Also called a module.

Variables

All variables are re-assignable (not immutable):

x = 1
x = 2
print(x) # 2

Syntactic sugar for doing arithmetic at the same time as a re-assignment are:

  • +=

  • -=

  • *=

To dynamically set a variable using a user's input in a CLI, you have the input function:

const name = input("What is your name? ")

Control flow

This is the basic syntax of if, else if, and else control flow:

if x == 2:
  # Execute first success case
elif x === 3:
  # Execute second success case
else:
  # Execute fallback case

Checking errors

Catching errors is just about using a try/except/else flow:

number = input('Please put in a number: ')

# Try to cast the number (could be "100" or "one hundred")
try:
  number = int(number)
# If casting fails, catch the error
except ValueError as e:
  print('Your input was not a number.')
  print(e)
# If casting succeeds, move forward
else:
  print('You input a number!', str(number))

Note: else clause is optional!

You may have noticed ValueError in the example above. Here are some of Python's most common types of errors:

  • SyntaxError

  • IndentationError

  • AssertionError (assertion failed in tests)

  • ValueError (function received inappropriate value)

  • NameError (invalid variable name used)

  • TypeError (function received inappropriate data type)

  • IndexError (index out of range in list)

  • KeyError (key not found in dictionary)

  • MemoryError (operation runs out of memory)

  • ZeroDivisionError (attempted to illegally divide a number by zero)

PreviousIntro To PythonNextIntro To Lists Loops And Functions

Last updated 3 years ago