30-Day Python Learning Plan – Day 1

30-Day Python Learning Plan – Day 1

Note: This series of notes is a study guide for the Python tutorial on GitHub: https://github.com/Asabeneh/30-Days-Of-Python

Introduction to Python

Python is a programming language that is very close to human language, with simple syntax that is easy to learn and use.

Installing Python: https://www.python.org/

Check if the installation was successful: Enter<span>python --version</span> (with a space in between) in the Mac terminal or Windows command prompt (cmd). If installed successfully, it will display the version information of the downloaded Python.

Features:

  • Python is an interpreted scripting language, so it does not require compilation.
  • Python comes with a Python Shell, which can be opened by entering:<span>python</span> in the Mac terminal or Windows command prompt (cmd).
    • Write Python code next to the prompt >>> and press enter to run the code.
    • Type exit() and press enter to exit the Python shell.

Installing VS Code

The Python Shell is suitable for testing small script codes, but it is not suitable for large projects. In a real working environment, developers use code editors for development.

Installation address: https://code.visualstudio.com/

Python development environment configuration:

Open VS Code and install Python
Return to the project view, create a new folder on the desktop or elsewhere, and then open it
Create a folder named Day1, then create a file named hello.py under Day1, print hello world, and run it
If the terminal appears as shown in the figure, it proves that the Python environment is configured successfully

Basics of Python

  • The file extension for Python files is .py

1. Indentation

In other programming languages, indentation is used to improve code readability, usually with curly braces to create code blocks. However, Python uses indentation to create code blocks.

2. Comments

  • Single-line comment: starts with #, for example:
# This is my first python script
# A # can only comment one line
# To write multiple lines, multiple # are needed
print('hello world')
  • Multi-line comment: starts with “”” and ends with “””, for example:
"""
This is a multi-line comment
It can span multiple lines
Between the two triple quotes
"""

3. Data Types

This is just a brief introduction to Python data types, not a detailed discussion.

1) Numeric

Includes three types: integers (e.g., 5), floating-point numbers (e.g., 3.5), and complex numbers (e.g., 1+2j).

2) Strings

Represented using single or double quotes. If the string spans multiple lines, triple quotes can be used.

# Example
str1='hello'
str2="What's your name"

3) Boolean

The boolean values in Python are True and False, where T and F must be uppercase.

4) Lists

A list is an ordered collection that can store different types of data. The data in a list is enclosed in [] brackets.

['banana',10,True,9.81]
# Storing different data types: string, integer, boolean, float

5) Dictionaries

The dictionary object in Python is an unordered collection stored in key-value pairs. The data in a dictionary is enclosed in {} brackets, with each element in the form of key:value.

{
'first_name':'Asabeneh',
'last_name':'Yetayeh',
'country':'Finland',
'age':25,
'skills':['JS', 'React', 'Node', 'Python']
}

6) Tuples

A tuple is an ordered collection, similar to a list, but once created, a tuple cannot be modified; it is immutable. The data in a tuple is enclosed in () brackets.

('Earth', 'Jupiter', 'Neptune', 'Mars', 'Venus', 'Saturn', 'Uranus', 'Mercury') # Planets

7) Sets

A set is a collection data type similar to lists and tuples. Unlike lists and tuples, sets are unordered collections and can only store one type.

{2, 4, 3, 5}
{3.14, 9.81, 2.7}
# The order in a set does not matter

8) Type Checking

The type() function in Python can be used to check the type.

print(type(5))
# Outputs int

Exercises

Exercise 1:

Open the Python Shell and perform the following operations: addition (+), subtraction (-), multiplication (*), modulus (%), division (/), exponentiation (**), integer division (//) (with operands 3 and 4).

Exercise 2:

Check the data types of the following data: 10, 9.8, 3.14, 4 – 4j, [‘Asabeneh’, ‘Python’, ‘Finland’]

Exercise 3:

Write an example for different Python data types, such as numbers (integers, floating-point numbers, complex numbers), strings, booleans, lists, tuples, sets, and dictionaries.

Leave a Comment