- Python is a free and open-source programming language.
- It was developed in the early 1990s by a Dutch programmer, Guido Van Rossum, who worked at Google from 2005 to 2012.
- The name "Python" was inspired by the British comedy group "Monty Python."
- It is pronounced as "Pay-thon."
- Large companies like Google, YouTube, and Yahoo! constantly require Python developers.
- Python can be used for desktop applications, games, mobile applications, web development, and networking.
- Python code is simple, easy to read, and does not need compilation.
- Python is cross-platform and can run on Linux, Windows, Mac OS X, MS-DOS, iOS, and Android. Note: Please read this article: link
- There are two main versions: Python 2 and Python 3.
- Python 3 is more powerful and has fewer errors compared to Python 2.
- Code written in Python 2 is not compatible with Python 3 and vice versa.
- Visit python.org and download the latest version.
- Install the downloaded file by following the setup instructions.
- Know the installation directory in case troubleshooting is needed.
Ensure you have an active Google account to access Google Colab. If you don’t have one, create a Google account.
While Google Colab eliminates the need for local installations, ensure your local machine has: - A modern browser (e.g., Chrome, Firefox, or Edge). - Stable internet connection.
Download the tutorial notebook provided for this session: - File
Name: Introduction_to_Python.ipynb - Download the
file.
For the other practices, please fetch the files:
Variables_and_Data_Types.ipynb - Download the
file
Operators_and_Expressions.ipynb - Download the
file
Control_Structures.ipynb - Download the
file
Data_Structures.ipynb - Download the
file
Functions_and_Modules.ipynb - Download the
file
- On Windows, Python is usually installed in:
C:\Users\YourUsername\AppData\Local\Programs\Python
- IDE (Integrated Development Environment) is a software for writing, editing, and debugging code efficiently.
- Popular Python Editors:
- Python IDLE (Basic editor, included with Python installation)
- Wing IDE (Download here)
- Canopy (Download here)
- PyCharm (Download here)
- Other editors: Sublime Text, Visual Studio, Jupyter Notebook, Spyder, Atom
- Compilers convert source code into machine code.
- Interpreters execute code line by line (Python is interpreted).
- Debuggers help find and fix errors.
- A variable stores data that can change.
- Constants store values that do not change.
- Example:
city = "New York" print(city) # Output: New York
- Cannot start with a number.
- Cannot contain special characters except
_(underscore). - No spaces allowed in variable names.
- Reserved keywords (e.g.,
True,and,class) cannot be used.
- String (
str) - Text data, written within quotes. - Integer (
int) - Whole numbers. - Float (
float) - Decimal numbers. - Boolean (
bool) - True or False values.
- Convert between different data types:
int("10") # Converts string "10" to integer 10 float(5) # Converts integer 5 to float 5.0 str(20) # Converts integer 20 to string "20"
- Used to display output:
print("Hello, World!") print(5 + 3) # Outputs 8
- Arithmetic Operators:
+,-,*,/,//,%,** - Comparison Operators:
==,!=,>,<,>=,<= - Logical Operators:
and,or,not - Membership Operators:
in,not in
- Used to control the execution of code based on conditions.
age = int(input("Enter your age: ")) if age < 18: print("You are a minor.") elif age < 65: print("You are an adult.") else: print("You are a senior citizen.")
- For Loop: Iterates over a sequence.
for i in range(1, 6): print(i)
- While Loop: Repeats as long as the condition is true.
x = 1 while x <= 5: print(x) x += 1
- Break Statement: Exits the loop early.
- Continue Statement: Skips the rest of the code inside the loop and moves to the next iteration.
- Ordered, mutable collection of items.
fruits = ["apple", "banana", "cherry"] print(fruits[0]) # Output: apple
- Ordered but immutable collections.
colors = ("red", "green", "blue") print(colors[1]) # Output: green
- Store key-value pairs.
person = {"name": "Alice", "age": 25} print(person["name"]) # Output: Alice
- Used to organize reusable blocks of code.
def greet(name): print("Hello, " + name + "!") greet("Alice") # Output: Hello, Alice!
- Python has built-in modules that provide extra functionality.
import math print(math.sqrt(16)) # Output: 4.0
- Generate random numbers.
import random print(random.randint(1, 10)) # Random number between 1 and 10
This concludes our six-class lecture series on Python programming!