Day 1 — Python Introduction Journey 🐍

Akshay Gawande
Data Shastra
Published in
11 min readAug 18, 2023

Welcome to the world of Python! 🌟

Agenda:

  1. What is Programming?
  2. Why do we write programs?
  3. What are the Different Types of Programming Languages?
  4. Why Python?

1. What is Programming?

Programming is the process of creating sets of instructions or code that tells a computer how to perform specific tasks. It involves writing, testing, and debugging code to solve problems or automate tasks. Programmers use programming languages to communicate with computers, providing them with step-by-step instructions to execute.

Programming requires logical thinking, problem-solving skills, and attention to detail. It involves breaking down complex problems into smaller, manageable steps and implementing algorithms and data structures to solve those problems efficiently.

2. Why do we write programs?

We write programs to solve problems, automate tasks, and create software that performs specific functions. Here are a few reasons why programming is essential:

Photo by The 77 Human Needs System on Unsplash
  1. Automation: Programs allow us to automate repetitive tasks, saving time and effort. From automating data processing to controlling complex machinery, programming enables efficiency and productivity.
  2. Problem-Solving: Programming is a powerful tool for problem-solving. It allows us to devise algorithms and implement logical solutions to various challenges, ranging from mathematical calculations to complex business problems.
  3. Software Development: Programs form the foundation of software development. By writing code, programmers create applications, websites, mobile apps, games, and other software that fulfill specific needs and provide valuable services.
  4. Data Analysis: Programming enables data analysis by allowing us to manipulate, process, and extract insights from large datasets. Through programming, we can develop algorithms and models to analyze data, identify patterns, and make informed decisions.
  5. Innovation: Programs are at the heart of technological innovation. From artificial intelligence and machine learning to virtual reality and the Internet of Things (IoT), programming drives advancements in various fields, pushing the boundaries of what’s possible.

3. What is a Programming Language?

A programming language is a formal language that enables humans to communicate instructions to computers. It serves as a medium for writing code that consists of a series of commands and statements to perform specific tasks or solve problems.

A programming language consists of a set of rules, syntax, and semantics (semantics refers to the meaning or interpretation of code) that define the structure and meaning of the code. It provides a way to express algorithms, logic, and computations in a format that computers can understand and execute.

Programmers use programming languages to write instructions that guide computers to perform various operations, manipulate data, make decisions, and interact with external systems. These instructions can range from simple calculations to complex algorithms, and they can control hardware devices, create software applications, analyze data, and much more.

Photo by Radowan Nakif Rehan on Unsplash

Programming languages come in various forms, such as high-level languages like Python, Java, and C++, which provide abstractions and simplify the programming process. Low-level languages, like assembly language, provide direct control over hardware resources but require more intricate coding.

Different programming languages have different strengths and are suited for different purposes. Some languages specialize in web development, data analysis, or artificial intelligence, while others are designed for systems programming or embedded systems. Each programming language has its own syntax, features, and ecosystem of libraries and tools.

In summary, a programming language is a formal system that allows programmers to communicate instructions to computers. It serves as a bridge between human-readable code and machine-executable instructions, enabling the development of software, applications, and systems to solve problems and automate tasks.

4. What are Different Types of Programming Languages?

Programming languages can be classified into various types based on their features and execution methods. Understanding these types helps us grasp the different ways code is executed. Let’s explore some common types and the role of interpreters and compilers:

Procedural Languages:

Procedural languages, such as C, Fortran, and Pascal, follow a sequential approach where programs are composed of procedures or functions that perform specific tasks. These languages can be compiled or interpreted. For example, C and Fortran are typically compiled languages, where the source code is transformed into machine code that can be directly executed. Pascal, on the other hand, can be both compiled and interpreted.

  • Examples: C, Fortran, Pascal
  • Characteristics: Follow a sequential approach, with programs composed of procedures or functions.
  • Execution: Can be compiled or interpreted.
Photo by Bradyn Trollip on Unsplash

Object-Oriented Languages:

Object-oriented languages, including Java, C++, and Python, organize code around objects that encapsulate data and behavior. These languages often use a combination of interpretation and compilation. For instance, Java and C++ are typically compiled into bytecode, which is then interpreted by the Java Virtual Machine (JVM) and C++ runtime environment, respectively. Python, in its standard implementation, is interpreted using the CPython interpreter, but it also supports the compilation of code into bytecode for improved performance.

  • Examples: Java, C++, Python
  • Characteristics: Organize code around objects that encapsulate data and behavior.
  • Execution: Often a combination of interpretation and compilation, where code is compiled into bytecode and then interpreted.

Functional Languages:

Functional languages, like Haskell, Lisp, and Erlang, focus on the evaluation of functions and emphasize immutability and pure functions. These languages can be either interpreted or compiled, depending on the specific implementation. For example, Haskell code is typically compiled into machine code for efficient execution, while Lisp and Erlang have interpreters that directly execute the source code.

  • Examples: Haskell, Lisp, Erlang
  • Characteristics: Focus on the evaluation of functions, emphasizing immutability and pure functions.
  • Execution: Can be interpreted or compiled, depending on the specific implementation.

Scripting Languages:

Scripting languages, such as Python, JavaScript, and Ruby, are often used for automation and quick prototyping. They are typically interpreted languages, executing code line by line through an interpreter. For instance, Python code is interpreted by the Python interpreter, JavaScript code is executed by web browsers through their JavaScript engines, and Ruby code is interpreted by the Ruby interpreter.

  • Examples: Python, JavaScript, Ruby
  • Characteristics: Used for automation and quick prototyping.
  • Execution: Typically interpreted, executing code line by line.

Markup Languages:

Markup languages like HTML and XML are not programming languages in the traditional sense. They define the structure and presentation of data, providing a standardized way to represent information for web pages, documents, and other purposes.

  • Examples: HTML, XML
  • Characteristics: Define the structure and presentation of data.
  • Execution: Not programming languages in the traditional sense; used to represent information for web pages and documents.

Domain-Specific Languages (DSLs):

DSLs are tailored for specific domains or industries. They can be implemented using various execution approaches, depending on the language’s design and purpose. Examples include SQL for querying databases and MATLAB for mathematical computations.

  • Examples: SQL, MATLAB
  • Characteristics: Tailored for specific domains or industries.
  • Execution: Varies based on the DSL’s design and purpose.

It’s worth noting that the interpretation and compilation aspects can vary across different programming languages. Some languages may have multiple implementations, offering a choice between interpretation and compilation, while others may primarily follow one approach.

In summary, programming languages exhibit various characteristics and execution methods. The choice between an interpreter and a compiler depends on the language’s design, its specific implementation, and the trade-offs between runtime performance, development speed, and portability. Understanding these nuances can help programmers select the most suitable language for their projects and optimize their code’s execution.

5. Why Python?

Let’s explain why Python is a popular programming language with simple words.

1. Readability: Python’s syntax is designed to be easy to read and understand, resembling plain English. Guido wanted to create a language with a clean and straightforward syntax, which would make it easy to read and understand the code. Python’s use of indentation for block structures and a lack of excessive punctuation contribute to its high readability.

This makes it simple for programmers to grasp the code’s logic quickly. For example:

# A simple Python program to calculate the sum of two numbers
num1 = 10
num2 = 20
sum_result = num1 + num2
print("The sum is:", sum_result)

2. Simplicity: Python was designed to be simple and intuitive. The language avoids unnecessary complexity, providing a straightforward approach to programming that allows developers to focus on solving problems rather than grappling with convoluted syntax.

Python aims to be straightforward, focusing on simplicity rather than complex syntax. This allows developers to write concise and clean code. The code is simple and achieves the desired task with just a few lines. For instance:

# A Python program to print the first 10 even numbers (start, end, steps)
for num in range(2, 21, 2):
print(num, end='\t')
//Program to print the first 10 even numbers in JAVA
public class PrintEvenNumbers{
public static void main(String[] args){
for (int num = 2; num <= 20; num+=2){
System.out.println(num+ "\t");
}
}
}

3. Versatility: Python is a versatile language, suitable for a wide range of applications. From web development to data analysis and machine learning, Python can handle various tasks. For example:

  • Web Development: Python frameworks like Django and Flask enable web application building.
  • Data Analysis: Python’s libraries like pandas and NumPy help process and analyze data efficiently.
  • Machine Learning: Python’s libraries like scikit-learn and TensorFlow empower the creation of machine learning models.
  • Web Scraping: Python’s ease of use and powerful libraries like Beautiful Soup and Scrapy make web scraping a breeze. You can extract data from websites effortlessly.
  • Desktop GUIs: Python offers libraries like Tkinter and PyQt for creating graphical user interfaces (GUIs) for desktop applications.

4. Community-Focused: Python was envisioned as a language that would foster a strong and inclusive community. Guido van Rossum believed that a collaborative and friendly community would contribute to the growth and success of the language.

5. Open Source: Python’s invention was driven by the philosophy of open-source software. Guido wanted Python to be freely available to all, allowing anyone to use, modify, and distribute the language.

Over the years, Python has grown in popularity, becoming one of the most widely used programming languages in the world. Its simplicity, readability, and versatility have made it a preferred choice for beginners, experienced developers, and professionals in various fields, from web development and data science to artificial intelligence and machine learning. Python’s success can be attributed to the vision and efforts of Guido van Rossum in creating a language that is both accessible and powerful.

To Sum up we can list below things why we choose Python as a programming language:

  1. Easy to Learn.
  2. Extensive Libraries
  3. Versatility.
  4. Strong Community.
  5. Cross-Platform Compatibility.
  6. High Demand in Industry.
  7. Open Source.

Things to Know:

1. Is Python an interpreted or compiled language? Let’s explain this with an example.

Python is both an interpreted and a compiled language. When you run a Python script, the Python interpreter reads the source code line by line and executes it directly. It translates the code into intermediate bytecode, which is then executed by the Python Virtual Machine (PVM). This interpreted nature allows for quick and interactive development, as changes in the code can be tested immediately without the need for a separate compilation step.

For example, consider the following simple Python code in a file named example.py:

The Python interpreter reads the code line by line and executes it, producing the desired output.

On the other hand, Python code can also be compiled into bytecode before execution. This compilation process generates bytecode files with a .pyc extension, which are platform-independent and can be executed on different systems without recompiling the source code.

To illustrate this, let’s use the same example.py script and compile it into bytecode:

2. Indentation:

Indentation is a crucial aspect of Python’s syntax and plays a significant role in defining the structure of the code. Unlike many other programming languages that use braces or brackets for code blocks, Python uses indentation to group statements within loops, conditionals, functions, and classes.

Example of Indentation:

def print_numbers():
# This is a function that prints numbers from 1 to 5
for i in range(1, 6):
print(i, end='\t') # Each statement inside the loop is indented by four spaces.

print('\nThis is how it works.')

print_numbers()
print('And out')

3. Comments:

In Python, comments are used to add explanatory notes to the code, making it easier for developers to understand and maintain. There are two types of comments in Python:

a. Single-line comments: These comments begin with the hash symbol (#) and extend to the end of the line. Single-line comments are useful for adding brief explanations or annotations to specific lines of code.

Example:

# This is a single-line comment
print("Hello, World!") # This line prints the greeting message

b. Multi-line comments (Docstrings): Multi-line comments, also known as docstrings, are used to provide documentation for functions, classes, and modules. They are enclosed within triple quotes (‘‘‘ ’’’ or “““ ”””) and can span multiple lines.

Example:

print('Hello World..!')
"""
This is how you can add multiple comments

They can be used in a function to provide documentation.

You can Use '''__''' as well
"""
print('\nGoood Mornning Mumbai :) ...!')

'''
Let's see how to use Escape Character
'''
print('\nThat\'s it.. ')

# That's a Wrap People
print('\nTata Bye-Bye Khatam Gaya..')

🚀 Exciting Beginnings, Python Explorers! 🐍

You’ve just embarked on a thrilling journey into the world of Python programming. From understanding the essence of programming to uncovering the allure of Python, you’ve taken significant strides today.

But this is just the prologue! 🌟 As we progress, we’ll dive deeper, unravel more Python magic, and create wonders through code. The realm of possibilities, from web development to machine learning, awaits your exploration.

So, keep your coding passion alive and your curiosity ignited. 🌈 The journey continues with more insights, tutorials, and projects that’ll transform you into a Python virtuoso.

Stay tuned, keep coding, and let’s embrace the power of Python together! 🚀🔥

#PythonAdventure #KeepCoding #StayCurious #Python #DataShastra #100DaysCode 🐍💡

--

--