Python - Colab notes
Python - Colab notes
ipynb - Colab
1. What is Python? Explain the features of Python and why it is a popular programming language.
=> Python is a high-level, interpreted programming language known for its simplicity, readability, and versatility. It was created by Guido van
Rossum and first released in 1991.
2. What are variables in Python? Explain with examples how to declare and use variables in Python.
=> Variables in Python are used to store data values. A variable acts as a symbolic name for a value and allows us to access and manipulate
that value throughout our program.
i. We don’t need to declare the type of a variable (Python is dynamically typed).
ii. A variable is created when we assign a value to it.
iii. Variable names are case-sensitive (name and Name are different).
iv. Must start with a letter or underscore (not a number).
v. Can include letters, digits, and underscores (_).
age = 25
print(age)
25
name = "Alice"
print(name)
Alice
x = 10
y = 5
sum = x + y
print("Sum is:", sum)
Sum is: 15
3. What is the use of the print() function in Python? Give examples using print() to display text, numbers, and variables.
=> The print() function in Python is used to display output on the screen. It sends data (text, numbers, variables, etc.) to the standard output
device, usually the console or terminal.
Key Uses of print():-
i. Displaying text messages.
ii. Showing the values of variables.
iii. Printing results of expressions.
iv. Combining strings and variables for readable output.
print("Hello, Python!")
Hello, Python!
https://colab.research.google.com/drive/13um1p86Dqbo-IbflSYyQZ8bWt6u_5yli#scrollTo=swDaV-evqLB5&printMode=true 1/3
5/20/25, 11:00 PM day1_AnjaliOjha_SeramporeGirlsCollege.ipynb - Colab
#This is an example of print() to display numbers
print(123)
print(3.14)
123
3.14
name = "Alice"
age = 25
print(name)
print(age)
Alice
25
4. What is an f-string in Python? Explain f-strings and give examples of how they are used to format strings with variables.
=> An f-string (formatted string literal) is a way to embed expressions (like variables) directly inside string literals using a concise and
readable syntax.
Some features of f-string are:-
i. Easy to insert variables into strings.
ii. Supports expressions, not just variables.
iii. More readable and efficient than older methods like str.format() or string concatenation.
name = "Alice"
age = 25
print(f"My name is {name} and I am {age} years old.")
pi = 3.14159
print(f"Value of pi: {pi:.2f}")
5. Write a Python program that declares two variables and uses both print() and f-string to display their values.
# Declare variables
name = "Alice"
age = 25
Name: Alice
Age: 25
My name is Alice and I am 25 years old.
https://colab.research.google.com/drive/13um1p86Dqbo-IbflSYyQZ8bWt6u_5yli#scrollTo=swDaV-evqLB5&printMode=true 2/3
5/20/25, 11:00 PM day1_AnjaliOjha_SeramporeGirlsCollege.ipynb - Colab
https://colab.research.google.com/drive/13um1p86Dqbo-IbflSYyQZ8bWt6u_5yli#scrollTo=swDaV-evqLB5&printMode=true 3/3