Day 1 of Python: Some fundamental aspects of Python.

Day 1 of Python: Some fundamental aspects of Python.

Hello, folks and welcome back to my blog! Today we're going to revise my Python concept. I am starting to learn fundamental concepts of Python then I'll go for advanced concepts.

Python is a dynamically typed, object-oriented programming language created by Guido Van Rossum in 1991.

Python was developed in the late 1980s by Guido van Rossum at Centrum Wiskunde & Informatica (CWI) in the Netherlands as a successor to the ABC programming language. It was inspired by SETL, capable of exception handling, and interfacing with the Amoeba operating system. The implementation of Python began in December 1989. The name "Python" was chosen by Guido van Rossum after the British comedy troupe Monty Python. He wanted a name that was short, memorable, and slightly mysterious, much like the language itself. While you might think of a python as a large snake, the name of the Python programming language comes from an old BBC television comedy sketch series called Monty Python's Flying Circus. you can see this picture

Python is a general-purpose, interpreted, high-level programming language. It supports object-oriented concepts, meaning it uses classes and objects. Python is dynamically typed, so the type of a variable is determined at runtime rather than being explicitly declared. It is relatively easy to learn and is often used as a first programming language.

Python is popular for web development, data science, machine learning, and artificial intelligence. It is a powerful and versatile language used by millions of people worldwide.

What is Shell

An operating system consists of various programs that perform tasks such as file handling, memory management, and resource management. These programs help our applications run smoothly.

Operating System Programs are of Two types, called Shell and Kernel programs.

Kernal programs are the ones that perform the actual task, like creating a file or sending interrupts. shell is another program whose job is to take input and decide and execute the required kernel program to do the job and show the output. The shell is called a command processor.

What is a terminal

The terminal is the program that interacts with the shell and allows us to communicate with it via text-based commands. This is why it is also called the command line.

What is Python shell?

Python is an interpreted language. This means that the Python interpreter reads a line of code, executes that line, and then repeats this process if there are no errors. The Python shell gives you a command line interface you can use to specify commands directly to the Python interpreter in an interactive manner.

The Python shell, also known as the Python interactive shell, is an interactive command-line interface (CLI) where you can execute Python code line by line and see the results immediately. It's a great tool for experimenting with Python code, debugging, and testing small code snippets quickly.

How to Access the Python shell

To start the Python shell, type 'python' and hit enter in the terminal.

The interactive shell is also called REPL which stands for read evaluate print loop. It'll need each command to evaluate and execute it, print the output for that command if any, and continue this same process repeatedly until you quit the shell.

You can access the Python shell in several ways:

  1. From the Command Line:

    • Open your terminal or command prompt.

    • Type python or python3 (depending on your installation) and press Enter.

python

You would see something like this:

Python 3.8.5 (default, Jul 21 2020, 10:48:26) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
  1. The >>> is the prompt indicating that the shell is ready to accept Python commands.

  2. Integrated Development Environments (IDEs):

    • Many IDEs like PyCharm, VS Code, and Jupyter Notebook have built-in Python shells or interactive consoles that you can use.

There are different ways to quit the shell:-

To exit the Python shell, you can type exit() or use the shortcut Ctrl + D (on Unix/Linux) or Ctrl + Z followed by Enter (on Windows).

What do you do in the Python shell?

You can do pretty much everything that the Python language allows from using variables, loops and conditions to defining functions and more.

The >>> is the shell prompt where you type in your commands. If you have commands that span across several lines for example when you define loops the shell prints the ... Character which signifies that a line continues.

Benefits of Using the Python Shell

  1. Immediate Feedback: You can see the results of your code immediately, which is useful for testing and debugging.

  2. Learning and Experimentation: It's a great environment for learning Python and experimenting with new code snippets.

  3. Prototyping: You can quickly prototype small parts of your program to see how they work.

    Examples

    Here's a quick example session in Python Shell:

     >>> print("Hello, World!")
     Hello, World!
     >>> x = 10
     >>> y = 5
     >>> x + y
     15
     >>> for i in range(3):
     ...     print(i)
     ... 
     0
     1
     2
     >>> def square(n):
     ...     return n * n
     ... 
     >>> square(4)
     16
     >>>exit()
    

What is Prompt in Python

In Python, a "prompt" generally refers to a message or string displayed to the user, asking for input. The prompt is typically used in conjunction with the input() function, which reads a line of text entered by the user and returns it as a string.

Using input() with a Prompt

The input() function can take an optional argument, which is the prompt string. This string is displayed to the user when the program is waiting for input.

Example

name = input("Enter your name: ")
print(f"Hello, {name}!")

When this script runs, the prompt "Enter your name: " will be displayed, and the user can type their name. After pressing Enter, the program will greet the user by name.

Detailed Explanation

  1. Prompt String: The string inside the input() function is called the prompt. It informs the user what kind of input is expected.

  2. User Input: The input() function waits for the user to type something and press Enter. Whatever the user types is returned as a string.

  3. Storing Input: The returned string can be stored in a variable for further use.

Conclusion

Python’s history is a testament to its success as a powerful, flexible, and easy-to-use programming language. Its evolution from a simple scripting language to a dominant force in various domains of software development highlights its robustness and adaptability. Python's emphasis on readability and community-driven development has ensured its position as a preferred language for both beginners and experienced developers, solidifying its place in the future of programming and technology.