Python fundamentals

Harison Gachuru

2/22/23

Basic data types

  • Integers e.g: -20
  • Floating-point numbers e.g: 0.5
  • Strings e.g: "Hello world!"
  • Boolean e.g: True

More data types

  • Lists e.g: ["Audi", "BMW", "Mercedes"]
  • Tuples e.g: ("SUV", "saloon/sedan", "hatchback")
  • Dictionaries e.g: {"make": "Suzuki", "model": "Alto"}
  • Sets e.g: {1, 2, 3, 5, 7}

Math operators

Operation Operator
Addition +
Subtraction -
Multiplication *
Division /
Integer division/floored quotient //
Modulus/remainder %
Exponentiation **

String operators

Operation Operator
Concatenation +
Replication *

Variables

Think of variables as containers for data.

Rules for creating valid variable names

  • Use only letters, numbers and underscores(_)
  • Don’t start with a number

Tips

  • The Python convention is to use snake-case, i.e: lower case letters and underscores
  • Use evocative names

Introduction to functions

  • Functions in Python are similar to Mathematical functions in that they take inputs and transform them to an output.

  • Some of the built-in functions include: type, print, input, int, str, float, dict, list, tuple, set

  • You can get access to other functions by importing them from the standard library or other installed packages

More resources