Initializing Core...
Initializing Core...
Operational
All modules in this domain are compiled below in order.
Welcome! This track covers Python fundamentals and popular libraries.
Python is one of the most popular programming languages. Itโs simple to use, packed with features and supported by a wide range of libraries and frameworks. Its clean syntax makes it beginner-friendly. It's
Install Python in your system.
What youโll learn
Tip: You can run most examples in a REPL:
pythonorpython3in your terminal.
We'll learn the syntax and variables used in Python.
Python has a very simple and clean syntax, which makes it beginner-friendly.
print("Hello, World!")
Thus prints - Hello, World! Input and Output :
name = input("Enter your name: ")print("Hello,", name, "! Welcome!")#Enter your name: Rohan#Hello, Rohan"! Welcome!
In Python, we assign variables some value. Below are a few examples.
x = 10 # intpi = 3.14 # floatname = "Zarine" # stris_ok = True # bool
๐ก In Python, variables are case-sensitive (Name and name are different).
This is how we assign multiple variables at the same time!
a, b, c = 1, 2, 3x = y = z = 0 # all assigned to 0
There are some rules to be followed while naming a variable.
Valid examples:
user_name = "Alice"marks1 = 90_total = 100
Invalid:
1value = 5 # โ cannot start with numberfor = 10 # โ cannot use keyword
Single line:
# This is a comment
Multi-line (docstring style):
"""This is amulti-line comment"""
Create three variables: age, pi, student_name. Assign appropriate values and print them.
Python comes with built-in data structures that make it powerful and easy to use.
fruits = ["apple", "banana", "cherry"]print(fruits[0]) # applefruits.append("mango")print(fruits) # ['apple', 'banana', 'cherry', 'mango']
Ordered, immutable, allow duplicates.
point = (10, 20)print(point[1]) # 20
Unordered, unique elements, no duplicates.
tags = {"python", "ml", "ece", "python"}print(tags) # {'ece', 'ml', 'python'}
Key-value pairs, unordered (insertion-ordered since Python 3.7).
student = {"name": "Rohan", "year": 2, "branch": "ECE"}print(student["name"]) # Rohanstudent["year"] = 3print(student) # {'name': 'Rohan', 'year': 3, 'branch': 'ECE'}
Functions let you organize code into reusable blocks.
We define a function in Python with the use of def(). Below is an example.
def greet():print("Hello, welcome to Python!")greet()
We pass parameters and arguments through functions like in the example below.
def add(a, b):return a + bresult = add(10, 5)print(result) # 15
def greet_user(name="Guest"):print(f"Hello, {name}!")greet_user() # Hello, Guest!greet_user("Zarine") # Hello, Zarine!
def student_info(name, branch, year):print(f"{name} studies {branch} in year {year}")student_info(branch="ECE", year=2, name="Zarine")
def add_all(*nums):return sum(nums)print(add_all(1, 2, 3, 4)) # 10
square = lambda x: x * xprint(square(5)) # 25
Now that you know variables, data structures, and functions, letโs build some small projects.
Uses variables + functions.
def add(a, b): return a + bdef sub(a, b): return a - bdef mul(a, b): return a * bdef div(a, b): return a / ba = int(input("Enter first number: "))b = int(input("Enter second number: "))print("Addition:", add(a, b))print("Subtraction:", sub(a, b))print("Multiplication:", mul(a, b))print("Division:", div(a, b))
Uses dictionaries + functions.
def add_student(name, branch, year):return {"name": name, "branch": branch, "year": year}student1 = add_student("Zarine", "ECE", 2)print(student1)
Uses lists + loops.
tasks = []def add_task(task):tasks.append(task)def show_tasks():print("Your Tasks:")for i, t in enumerate(tasks, 1):print(f"{i}. {t}")add_task("Study Python")add_task("Complete Assignment")show_tasks()
Uses strings + functions.
def word_count(text):words = text.split()return len(words)sentence = "Python makes programming fun"print("Word count:", word_count(sentence))
Uses loops + conditions + random module.
import randomsecret = random.randint(1, 10)guess = int(input("Guess a number (1-10): "))if guess == secret:print("๐ Correct!")else:print("โ Wrong! The number was", secret)