Python Introduction

What is Python?

  1. Is a high- level programming language, created by Guido Van Rossum - fondly known as Benevolent Dictator For Life

  2. It was first released in 1991. Today Python interpreters are available for many Operating Systems including Windows and Linux

  3. Python programmers are known as Pythonistas or Pythonists


Reasons for Popularity - Free, Software quality, Developer productivity, Program portability, Supports libraries, component integration and enjoyment.


Variable: Labeled boxes for storing and referencing data of different types. To create a variable, write its name on the left, followed by the assignment (=) operator and the value you want to store on the right.

Strings are written with single or double quotes.


Following Naming Rules

When naming variables in Python, there are some important rules you should keep in mind:

  • Variable names can only start with a letter or an underscore (_), not a number.

  • Variable names can only contain alphanumeric characters (a-z, A-Z, 0-9) and underscores (_).

  • Variable names are case-sensitive: age, Age, and AGE are all considered unique.

  • Variable names cannot be one of Python's reserved keywords such as if, class, or def.

Following Naming Conventions

First, variable names should be in lowercase, with words separated by an underscore. This is called snake case.

Next, you should use descriptive names for variables. For example, if you want to save a user's age as a variable, user_age is better than age or an abbreviation like ua

This way, you can easily communicate the purpose of a variable to other team members (or to your future self) in a large codebase.

Another convention is to avoid using single-letter variable names. Single-letter names are common in Python, but they should be avoided because they communicate no purpose or meaning.


Writing Comments

The pound symbol (#) and the text that follows it form a comment. Comments let you add notes and explanations to your code.

In Python, comments start with a pound symbol (#), and the language ignores everything after the # symbol on that line.

You can use comments to explain your code, leave reminders for yourself, or clarify why a line exists. Comments are especially helpful when you're learning or working in teams.


However, you shouldn't use comments to explain what your variable names mean. Instead, the names you choose for your variables should be descriptive and communicate what they're for, and follow the other naming rules mentioned earlier to prevent syntax errors.

The terminal is the area where you can see text output from a program.

Python includes print() as a built-in function, which means you can use it without defining it yourself. The print() function sends text and other values to the terminal.


A data type describes the kind of value a variable holds, for example, a number or a piece of text. Programming languages use data types so they know how to store and work with different kinds of information.

Types of Data Types:

  1. Integer: A whole number without decimals, for example, 10 or -5.

  2. Float: A number with a decimal point, like 4.41 or -0.4.

  3. String: A sequence of characters enclosed in single or double quotation marks like 'Hello world!'.

  4. Boolean: A true or false type, written as True or False.

To see what type x is, you can use the type() function. If you fail to provide any arguments to the type() function, then you will receive the error message.

The built-in isinstance() function lets you check if a variable matches a specific data type. It takes a value and the type you want to check it against, then returns a boolean. The isinstance() function also allows you to check for multiple types at once.

  1. type(): The type() function tells you the exact type of an object.

  2. isinstance(): The isinstance() function checks whether an object belongs to a particular data type. It returns either True or False.


STRINGS: A string is a sequence of characters surrounded by either single or double quotation marks. Python treats both forms as strings, so you can use either one.

Python provides the in operator, which returns a boolean that specifies whether the character or characters exist in the string or not.