01 | Introduction and Basics
>> Why Should You Learn Python?
- Ease of Learning: Python is known for its simple and readable syntax, making it the easiest programming language to learn.
- Top Popularity: Python consistently ranks as the most popular programming language in the world.
- Competitive Salary: New developers can earn a starting salary of approximately for entry-level positions in the USA offering around $5,000 per month (according to Glassdoor).
>> History of Python
- Creator: Developed by Guido van Rossum, a Dutch programmer.
- Initial Release: First launched in 1991.
- Name Origin: Inspired by the British comedy show “Monty Python’s Flying Circus.”
>> Key Features of Python
- General Purpose: Python is versatile and can be used across various application domains without being limited to any specific area.
- Open Source: The source code is freely available for modification and redistribution, fostering a collaborative development environment.
- Interpreted Language: Unlike compiled languages, Python code is executed line-by-line, making debugging easier and faster.
- High-Level: Python abstracts complex details, allowing developers to write clear and concise code.
- Easy to Read, Write, and Maintain: Python’s syntax is designed to be readable and straightforward, reducing the learning curve and simplifying maintenance.
- Rich Libraries: Python boasts an extensive standard library and numerous third-party packages, providing tools for virtually any task.
- Portable: Python code can run on different operating systems without modification.
- Dynamic Programming: Python supports dynamic typing and binding, making it flexible and easy to use.
- Object-Oriented Programming: Python supports OOP paradigms, allowing for the creation of reusable and organized code.
- Functional-Oriented Programming: Python also supports functional programming, enabling the use of functions as first-class objects.
>> Setup Introduction
To get started with Python, you’ll need the following tools:
- Python Interpreter: The core program that executes Python code. Download it from python.org.
- Integrated Development Environment (IDE): A tool to write and manage your code efficiently. Popular choices include PyCharm, VS Code, and Jupyter Notebook.
- Terminal: Use the terminal or command prompt to run your Python scripts and manage your development environment.
>> Installation Guide
- Python: Download and install the latest version of Python from python.org.
- IDE (Integrated Development Environment): Choose and install an IDE to write and manage your code efficiently. Popular options include:
- PyCharm: A powerful, feature-rich IDE tailored for Python development.
- Visual Studio Code: A versatile, lightweight code editor with extensive Python support through extensions.
>> Basic Syntax
Using the Print Function
- Open Your IDE: Launch PyCharm or Visual Studio Code.
- Write Your First Python Code:
Python
Python
# Print function
print(“Hello, Python!“)
print(“Hello, Python!“)
- Run Your First Python Code:
- Using the Terminal:
- Open the terminal or command prompt in your IDE.
- Navigate to the directory where your Python file is saved.
- Run the script by typing:
python your_script_name.py
- Using the Terminal:
Escape Characters in Python
Escape Characters in Python
Escape characters allow you to include special characters in your strings. Here are some commonly used escape characters:
\\
– Backslash\'
– Single quote\"
– Double quote\n
– New line\t
– Horizontal tab\b
– Backspace\ooo
– Octal value\xhh
– Hexadecimal value
Examples:
New Line Character (
\n
):
Python
Python
# \n – new line character
print(“Hello\nPython!“)
print(“Hello\nPython!“)
Horizontal Tab (
\t
):
Python
Python
# \t – horizontal tab
print(“Name\t: Hello“)
print(“City\t: Python“)
print(“Name\t: Hello“)
print(“City\t: Python“)
- Backspace (
\b
):
Python
Python
# \b – backspace
print(“Hello\bPython!“)
print(“Hello\bPython!“)
Quotation Mark (
\"
):
Python
Python
# \” – double quote
print(“Hello\”Python\”“)
print(“Hello\”Python\”“)